Skip to content
Permalink
Browse files

Nicer behaviour of QgsCharacterSelectorDialog

  • Loading branch information
nyalldawson committed May 2, 2019
1 parent 25f20f4 commit 1d258d53c6a5d711869293e00386be3eb6d90b57
@@ -23,7 +23,13 @@ A dialog for selecting a single character from a single font
QgsCharacterSelectorDialog( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

public slots:
const QChar &selectCharacter( bool *gotChar, const QFont &font, const QString &style );

QChar selectCharacter( bool *gotChar, const QFont &font, const QString &style, QChar initialSelection = QChar() );
%Docstring
Opens the dialog modally and returns when the user has selected a character.

If ``initialSelection`` is specified, then that character will be initially selected in the dialog.
%End

protected:
};
@@ -29,14 +29,16 @@ QgsCharacterSelectorDialog::QgsCharacterSelectorDialog( QWidget *parent, Qt::Win
connect( mCharWidget, &CharacterWidget::characterSelected, this, &QgsCharacterSelectorDialog::setCharacter );
}

const QChar &QgsCharacterSelectorDialog::selectCharacter( bool *gotChar, const QFont &font, const QString &style )
QChar QgsCharacterSelectorDialog::selectCharacter( bool *gotChar, const QFont &font, const QString &style, QChar initialSelection )
{
mCharSelectLabelFont->setText( QStringLiteral( "%1 %2" ).arg( font.family(), style ) );
mCharWidget->setFont( font );
mCharWidget->setFontStyle( style );
mCharWidget->setFontSize( 22.0 );
mCharSelectScrollArea->viewport()->update();

mCharWidget->setCharacter( initialSelection );

QApplication::setOverrideCursor( Qt::ArrowCursor );
int res = exec();
QApplication::restoreOverrideCursor();
@@ -39,7 +39,13 @@ class GUI_EXPORT QgsCharacterSelectorDialog : public QDialog, private Ui::QgsCha
QgsCharacterSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

public slots:
const QChar &selectCharacter( bool *gotChar, const QFont &font, const QString &style );

/**
* Opens the dialog modally and returns when the user has selected a character.
*
* If \a initialSelection is specified, then that character will be initially selected in the dialog.
*/
QChar selectCharacter( bool *gotChar, const QFont &font, const QString &style, QChar initialSelection = QChar() );

private slots:
void setCharacter( QChar chr );
@@ -1411,7 +1411,9 @@ void QgsTextFormatWidget::mPreviewBackgroundBtn_colorChanged( const QColor &colo
void QgsTextFormatWidget::mDirectSymbLeftToolBtn_clicked()
{
bool gotChar = false;
QChar dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ) );

const QChar initial = !mDirectSymbLeftLineEdit->text().isEmpty() ? mDirectSymbLeftLineEdit->text().at( 0 ) : QChar();
QChar dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ), initial );

if ( !gotChar )
return;
@@ -1423,7 +1425,8 @@ void QgsTextFormatWidget::mDirectSymbLeftToolBtn_clicked()
void QgsTextFormatWidget::mDirectSymbRightToolBtn_clicked()
{
bool gotChar = false;
QChar dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ) );
const QChar initial = !mDirectSymbRightLineEdit->text().isEmpty() ? mDirectSymbRightLineEdit->text().at( 0 ) : QChar();
QChar dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ), initial );

if ( !gotChar )
return;
@@ -112,7 +112,7 @@ void CharacterWidget::setColumns( int columns )
void CharacterWidget::setCharacter( QChar character )
{
const bool changed = character != mLastKey;
mLastKey = character.unicode();
mLastKey = character.isNull() ? -1 : character.unicode();
QWidget *widget = parentWidget();
if ( widget )
{
@@ -123,7 +123,7 @@ void CharacterWidget::setCharacter( QChar character )
}
}
if ( changed )
emit characterSelected( mLastKey );
emit characterSelected( mLastKey >= 0 ? QChar( mLastKey ) : QChar() );

update();
}

0 comments on commit 1d258d5

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