Skip to content

Commit

Permalink
+ improve handling of default colors of report view and Python consol…
Browse files Browse the repository at this point in the history
…e when using style sheets
  • Loading branch information
wwmayer committed Jan 31, 2014
1 parent a7d297c commit d927d0b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/Gui/PythonConsole.cpp
Expand Up @@ -852,6 +852,14 @@ void PythonConsole::changeEvent(QEvent *e)
this, SLOT(visibilityChanged(bool)));
}
}
else if (e->type() == QEvent::StyleChange) {
QPalette pal = palette();
QColor color = pal.windowText().color();
unsigned long text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
// if this parameter is not already set use the style's window text color
text = getWindowParameter()->GetUnsigned("Text", text);
getWindowParameter()->SetUnsigned("Text", text);
}
TextEdit::changeEvent(e);
}

Expand Down
17 changes: 0 additions & 17 deletions src/Gui/PythonEditor.cpp
Expand Up @@ -47,7 +47,6 @@ using namespace Gui;
namespace Gui {
struct PythonEditorP
{
QMap<QString, QColor> colormap; // Color map
int debugLine;
QRect debugRect;
QPixmap breakpoint;
Expand All @@ -60,22 +59,6 @@ struct PythonEditorP
debugMarker(QLatin1String(":/icons/debug-marker.png"))
{
debugger = Application::Instance->macroManager()->debugger();

colormap[QLatin1String("Text")] = Qt::black;
colormap[QLatin1String("Bookmark")] = Qt::cyan;
colormap[QLatin1String("Breakpoint")] = Qt::red;
colormap[QLatin1String("Keyword")] = Qt::blue;
colormap[QLatin1String("Comment")] = QColor(0, 170, 0);
colormap[QLatin1String("Block comment")] = QColor(160, 160, 164);
colormap[QLatin1String("Number")] = Qt::blue;
colormap[QLatin1String("String")] = Qt::red;
colormap[QLatin1String("Character")] = Qt::red;
colormap[QLatin1String("Class name")] = QColor(255, 170, 0);
colormap[QLatin1String("Define name")] = QColor(255, 170, 0);
colormap[QLatin1String("Operator")] = QColor(160, 160, 164);
colormap[QLatin1String("Python output")] = QColor(170, 170, 127);
colormap[QLatin1String("Python error")] = Qt::red;
colormap[QLatin1String("Current line highlight")] = QColor(224,224,224);
}
};
} // namespace Gui
Expand Down
16 changes: 15 additions & 1 deletion src/Gui/ReportView.cpp
Expand Up @@ -121,7 +121,8 @@ struct TextBlockData : public QTextBlockUserData
ReportHighlighter::ReportHighlighter(QTextEdit* edit)
: QSyntaxHighlighter(edit), type(Message)
{
txtCol = Qt::black;
QPalette pal = edit->palette();
txtCol = pal.windowText().color();
logCol = Qt::blue;
warnCol = QColor(255, 170, 0);
errCol = Qt::red;
Expand Down Expand Up @@ -372,6 +373,19 @@ void ReportOutput::customEvent ( QEvent* ev )
}
}

void ReportOutput::changeEvent(QEvent *ev)
{
if (ev->type() == QEvent::StyleChange) {
QPalette pal = palette();
QColor color = pal.windowText().color();
unsigned long text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
// if this parameter is not already set use the style's window text color
text = getWindowParameter()->GetUnsigned("colorText", text);
getWindowParameter()->SetUnsigned("colorText", text);
}
QTextEdit::changeEvent(ev);
}

void ReportOutput::contextMenuEvent ( QContextMenuEvent * e )
{
QMenu* menu = createStandardContextMenu();
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/ReportView.h
Expand Up @@ -157,6 +157,8 @@ class GuiExport ReportOutput : public QTextEdit, public WindowParameter, public
protected:
/** For internal use only */
void customEvent ( QEvent* ev );
/** Handles the change of style sheets */
void changeEvent(QEvent *);
/** Pops up the context menu with some extensions */
void contextMenuEvent ( QContextMenuEvent* e );

Expand Down
4 changes: 3 additions & 1 deletion src/Gui/TextEdit.cpp
Expand Up @@ -304,7 +304,9 @@ void TextEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::black);
QPalette pal = palette();
QColor color = pal.windowText().color();
painter.setPen(color);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
drawMarker(blockNumber + 1, 1, top, &painter);
Expand Down

0 comments on commit d927d0b

Please sign in to comment.