QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscharacterselectordialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscharacterselectordialog.cpp - single font character selector dialog
3 
4  ---------------------
5  begin : November 2012
6  copyright : (C) 2012 by Larry Shaffer
7  email : larrys at dakcarto dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "characterwidget.h"
19 
20 
21 QgsCharacterSelectorDialog::QgsCharacterSelectorDialog( QWidget *parent, Qt::WindowFlags fl )
22  : QDialog( parent, fl )
23  , mChar( QChar::Null )
24 {
25  setupUi( this );
26  mCharWidget = new CharacterWidget( this );
27  mCharSelectScrollArea->setWidget( mCharWidget );
28  mCharSelectScrollArea->setVerticalOnly( true );
29  connect( mCharWidget, &CharacterWidget::characterSelected, this, &QgsCharacterSelectorDialog::setCharacter );
30 }
31 
32 QChar QgsCharacterSelectorDialog::selectCharacter( bool *gotChar, const QFont &font, const QString &style, QChar initialSelection )
33 {
34  mCharSelectLabelFont->setText( QStringLiteral( "%1 %2" ).arg( font.family(), style ) );
35  mCharWidget->setFont( font );
36  mCharWidget->setFontStyle( style );
37  mCharWidget->setFontSize( 22.0 );
38  mCharSelectScrollArea->viewport()->update();
39 
40  mCharWidget->setCharacter( initialSelection );
41 
42  QApplication::setOverrideCursor( Qt::ArrowCursor );
43  int res = exec();
44  QApplication::restoreOverrideCursor();
45 
46  if ( res == QDialog::Accepted )
47  {
48  if ( !mChar.isNull() && gotChar )
49  {
50  *gotChar = true;
51  }
52  }
53  return mChar;
54 }
55 
56 void QgsCharacterSelectorDialog::setCharacter( QChar chr )
57 {
58  mChar = chr;
59 }
CharacterWidget::setFont
void setFont(const QFont &font)
Sets the font to show in the widget.
Definition: characterwidget.cpp:66
CharacterWidget
A widget for displaying characters available in a preset font, and allowing users to select an indivi...
Definition: characterwidget.h:70
characterwidget.h
CharacterWidget::characterSelected
void characterSelected(QChar character)
Emitted when a character is selected in the widget.
QgsCharacterSelectorDialog::mChar
QChar mChar
Definition: qgscharacterselectordialog.h:54
CharacterWidget::setFontStyle
void setFontStyle(const QString &fontStyle)
Sets the font style to show in the widget.
Definition: characterwidget.cpp:82
qgscharacterselectordialog.h
QgsCharacterSelectorDialog::selectCharacter
QChar selectCharacter(bool *gotChar, const QFont &font, const QString &style, QChar initialSelection=QChar())
Opens the dialog modally and returns when the user has selected a character.
Definition: qgscharacterselectordialog.cpp:32
CharacterWidget::setCharacter
void setCharacter(QChar character)
Sets the currently selected character in the widget.
Definition: characterwidget.cpp:112
CharacterWidget::setFontSize
void setFontSize(double fontSize)
Sets the font size (in points) to render in the widget.
Definition: characterwidget.cpp:74
QgsCharacterSelectorDialog::mCharWidget
CharacterWidget * mCharWidget
Definition: qgscharacterselectordialog.h:55
QgsCharacterSelectorDialog::QgsCharacterSelectorDialog
QgsCharacterSelectorDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Definition: qgscharacterselectordialog.cpp:21