Skip to content
Permalink
Browse files

[ui] Improvements to the font marker character widget

- Declare a minimum height to avoid narrow selection area
- Use application color palette instead of hardcoded values
- Decrease number of columns to better fit in the style dock
  • Loading branch information
nirvn committed Apr 29, 2019
1 parent c0b2ba1 commit 405efd8ac9048170a7be4b561a76bde7485e85c0
@@ -43,6 +43,9 @@
**
****************************************************************************/

#include "characterwidget.h"
#include "qgsapplication.h"

#include <QFontDatabase>
#include <QMouseEvent>
#include <QPaintEvent>
@@ -51,8 +54,6 @@
#include <QPoint>
#include <QToolTip>

#include "characterwidget.h"

CharacterWidget::CharacterWidget( QWidget *parent )
: QWidget( parent )
{
@@ -62,15 +63,15 @@ CharacterWidget::CharacterWidget( QWidget *parent )
void CharacterWidget::setFont( const QFont &font )
{
mDisplayFont.setFamily( font.family() );
mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
mSquareSize = std::max( 34, QFontMetrics( mDisplayFont ).xHeight() * 3 );
adjustSize();
update();
}

void CharacterWidget::setFontSize( double fontSize )
{
mDisplayFont.setPointSizeF( fontSize );
mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
mSquareSize = std::max( 34, QFontMetrics( mDisplayFont ).xHeight() * 3 );
adjustSize();
update();
}
@@ -81,7 +82,7 @@ void CharacterWidget::setFontStyle( const QString &fontStyle )
const QFont::StyleStrategy oldStrategy = mDisplayFont.styleStrategy();
mDisplayFont = fontDatabase.font( mDisplayFont.family(), fontStyle, mDisplayFont.pointSize() );
mDisplayFont.setStyleStrategy( oldStrategy );
mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
mSquareSize = std::max( 34, QFontMetrics( mDisplayFont ).xHeight() * 3 );
adjustSize();
update();
}
@@ -144,7 +145,8 @@ void CharacterWidget::mousePressEvent( QMouseEvent *event )
void CharacterWidget::paintEvent( QPaintEvent *event )
{
QPainter painter( this );
painter.fillRect( event->rect(), QBrush( Qt::white ) );
QPalette palette = qApp->palette();
painter.fillRect( event->rect(), QBrush( palette.color( QPalette::Base ) ) );
painter.setFont( mDisplayFont );

QRect redrawRect = event->rect();
@@ -153,7 +155,7 @@ void CharacterWidget::paintEvent( QPaintEvent *event )
int beginColumn = redrawRect.left() / mSquareSize;
int endColumn = redrawRect.right() / mSquareSize;

painter.setPen( QPen( Qt::gray ) );
painter.setPen( QPen( palette.color( QPalette::Mid ) ) );
for ( int row = beginRow; row <= endRow; ++row )
{
for ( int column = beginColumn; column <= endColumn; ++column )
@@ -163,18 +165,16 @@ void CharacterWidget::paintEvent( QPaintEvent *event )
}

QFontMetrics fontMetrics( mDisplayFont );
painter.setPen( QPen( Qt::black ) );
for ( int row = beginRow; row <= endRow; ++row )
{

for ( int column = beginColumn; column <= endColumn; ++column )
{

int key = row * mColumns + column;
painter.setClipRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
painter.setPen( QPen( palette.color( key == mLastKey ? QPalette::HighlightedText : QPalette::WindowText ) ) );

if ( key == mLastKey )
painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( Qt::red ) );
painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( palette.color( QPalette::Highlight ) ) );

painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.width( QChar( key ) ) / 2,
row * mSquareSize + 4 + fontMetrics.ascent(),
@@ -154,7 +154,7 @@ class GUI_EXPORT CharacterWidget : public QWidget

private:
QFont mDisplayFont;
int mColumns = 16;
int mColumns = 13;
int mLastKey = -1;
int mSquareSize = 24;
};
@@ -3207,6 +3207,7 @@ QgsFontMarkerSymbolLayerWidget::QgsFontMarkerSymbolLayerWidget( QgsVectorLayer *
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMetersInMapUnits << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

widgetChar = new CharacterWidget;
scrollArea->setWidget( widgetChar );

@@ -321,6 +321,12 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QgsScrollArea" name="scrollArea">
<property name="minimumSize">
<size>
<width>0</width>
<height>158</height>
</size>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>

0 comments on commit 405efd8

Please sign in to comment.
You can’t perform that action at this time.