Skip to content

Commit

Permalink
Force GRASS shell font by setStyleSheet, hopefully fixes #7340; added…
Browse files Browse the repository at this point in the history
… black on white scheme
  • Loading branch information
blazek committed Jun 7, 2013
1 parent 15e3fc3 commit 4c5c159
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassshell.cpp
Expand Up @@ -59,7 +59,7 @@ QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const ch
#endif

mTerminal->setSize( 80, 25 );
mTerminal->setColorScheme( COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW );
mTerminal->setColorScheme( COLOR_SCHEME_BLACK_ON_WHITE );
mTerminal->startShellProgram();
mTerminal->setFocus( Qt::MouseFocusReason );
}
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/grass/qtermwidget/ColorTables.h
Expand Up @@ -64,5 +64,20 @@ static const ColorEntry blackonlightyellow_color_table[TABLE_COLORS] =
ColorEntry( QColor( 84, 255, 255 ), 0, 0 ), ColorEntry( QColor( 255, 255, 255 ), 0, 0 )
};

// copy of blackonlightyellow_color_table with background set to white
static const ColorEntry blackonwhite_color_table[TABLE_COLORS] =
{
ColorEntry( QColor( 0, 0, 0 ), 0, 0 ), ColorEntry( QColor( 255, 255, 255 ), 1, 0 ),
ColorEntry( QColor( 0, 0, 0 ), 0, 0 ), ColorEntry( QColor( 178, 24, 24 ), 0, 0 ),
ColorEntry( QColor( 24, 178, 24 ), 0, 0 ), ColorEntry( QColor( 178, 104, 24 ), 0, 0 ),
ColorEntry( QColor( 24, 24, 178 ), 0, 0 ), ColorEntry( QColor( 178, 24, 178 ), 0, 0 ),
ColorEntry( QColor( 24, 178, 178 ), 0, 0 ), ColorEntry( QColor( 178, 178, 178 ), 0, 0 ),
ColorEntry( QColor( 0, 0, 0 ), 0, 1 ), ColorEntry( QColor( 255, 255, 221 ), 1, 0 ),
ColorEntry( QColor( 104, 104, 104 ), 0, 0 ), ColorEntry( QColor( 255, 84, 84 ), 0, 0 ),
ColorEntry( QColor( 84, 255, 84 ), 0, 0 ), ColorEntry( QColor( 255, 255, 84 ), 0, 0 ),
ColorEntry( QColor( 84, 84, 255 ), 0, 0 ), ColorEntry( QColor( 255, 84, 255 ), 0, 0 ),
ColorEntry( QColor( 84, 255, 255 ), 0, 0 ), ColorEntry( QColor( 255, 255, 255 ), 0, 0 )
};

#endif

6 changes: 5 additions & 1 deletion src/plugins/grass/qtermwidget/TerminalDisplay.cpp
Expand Up @@ -1082,9 +1082,13 @@ void TerminalDisplay::paintEvent( QPaintEvent* pe )
QPainter paint( this );
//qDebug("%s %d paintEvent %d %d", __FILE__, __LINE__, paint.window().top(), paint.window().right());

const QColor background = _colorTable[DEFAULT_BACK_COLOR].color;
foreach ( QRect rect, ( pe->region() & contentsRect() ).rects() )
{
drawBackground( paint, rect, palette().background().color(), true /* use opacity setting */ );
// setStyleSheet() changes background color -> use default
//drawBackground( paint, rect, palette().background().color(), true /* use opacity setting */ );
drawBackground( paint, rect, background, true );

drawContents( paint, rect );
}
// drawBackground(paint,contentsRect(),palette().background().color(), true /* use opacity setting */);
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/grass/qtermwidget/qtermwidget.cpp
Expand Up @@ -114,6 +114,14 @@ void QTermWidget::init()
{
m_impl->m_terminalDisplay->setSize( 80, 40 );

// QWidget::setFont() does not guarantee to really change the font (see doc)
// setStyleSheet() however should force the font change, it has however some
// some side efects like changing background color
if ( m_impl->m_terminalDisplay )
{
m_impl->m_terminalDisplay->setStyleSheet( "font-size: 10pt; font-family: Monospace;" );

This comment has been minimized.

Copy link
@dakcarto

dakcarto Jun 7, 2013

Member

Hi Radim,

Sometimes the current parent style cascades better when defining the class for the style, e.g. try:
m_impl->m_terminalDisplay->setStyleSheet( "TerminalDisplay { font-size: 10pt; font-family: Monospace; }" );

to see if it gets rid of the side effects. Just guessing here, though, since I don't use the GRASS plugin's terminal on this machine.

}

QFont font = QApplication::font();
font.setFamily( "Monospace" );
font.setPointSize( 10 );
Expand Down Expand Up @@ -181,6 +189,9 @@ void QTermWidget::setColorScheme( int scheme )
case COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW:
m_impl->m_terminalDisplay->setColorTable( blackonlightyellow_color_table );
break;
case COLOR_SCHEME_BLACK_ON_WHITE:
m_impl->m_terminalDisplay->setColorTable( blackonwhite_color_table );
break;
default: //do nothing
break;
};
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/grass/qtermwidget/qtermwidget.h
Expand Up @@ -27,7 +27,8 @@ struct TermWidgetImpl;

enum COLOR_SCHEME { COLOR_SCHEME_WHITE_ON_BLACK = 1,
COLOR_SCHEME_GREEN_ON_BLACK,
COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW
COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW,
COLOR_SCHEME_BLACK_ON_WHITE
};

class QTermWidget : public QWidget
Expand Down Expand Up @@ -138,7 +139,7 @@ class QTermWidget : public QWidget
#ifdef __cplusplus
extern "C"
#endif
void *createTermWidget( int startnow, void *parent );
void *createTermWidget( int startnow, void *parent );

#endif

0 comments on commit 4c5c159

Please sign in to comment.