summaryrefslogtreecommitdiff
path: root/src/settings/FontColorSettingsDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/FontColorSettingsDialog.cpp')
-rw-r--r--src/settings/FontColorSettingsDialog.cpp300
1 files changed, 300 insertions, 0 deletions
diff --git a/src/settings/FontColorSettingsDialog.cpp b/src/settings/FontColorSettingsDialog.cpp
new file mode 100644
index 0000000..beb5f01
--- /dev/null
+++ b/src/settings/FontColorSettingsDialog.cpp
@@ -0,0 +1,300 @@
+#include "FontColorSettingsDialog.h"
+#include "ColorBox.h"
+#include "../dic-options/FieldsPreviewModel.h"
+#include "StylesListModel.h"
+#include "StylePreviewModel.h"
+
+#include <QtCore>
+
+FontColorSettingsDialog::FontColorSettingsDialog(QWidget *parent) :
+ QDialog(parent), m_curStyle( NULL )
+ {
+ initData();
+ QHBoxLayout* bgColorLt = createBgColorSelector();
+ QLabel* stylesLbl = createStylesList();
+ QVBoxLayout* styleLt = createStyleControls();
+ createKeywordBox( styleLt );
+ styleLt->addStretch();
+ QLabel* previewLbl = createStylePreview();
+
+ m_okCancelBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+ QDialogButtonBox::RestoreDefaults, Qt::Horizontal );
+ connect( m_okCancelBox, SIGNAL(accepted()), this, SLOT(accept()) );
+ connect( m_okCancelBox, SIGNAL(rejected()), this, SLOT(reject()) );
+ connect( m_okCancelBox, SIGNAL(clicked(QAbstractButton*)), SLOT(dialogButtonClicked(QAbstractButton*)) );
+
+ QGridLayout* mainLt = new QGridLayout;
+ mainLt->addLayout( bgColorLt, 0, 0, 1, 2 );
+ mainLt->addWidget( stylesLbl, 1, 0 );
+ mainLt->addWidget( m_stylesListView, 2, 0 );
+ mainLt->addLayout( styleLt, 2, 1 );
+ mainLt->addWidget( previewLbl, 1, 2 );
+ mainLt->addWidget( m_stylesPreview, 2, 2 );
+ mainLt->addWidget( m_okCancelBox, 3, 0, 1, 3 );
+
+ setLayout( mainLt );
+ setWindowTitle( tr("Font & color settings") );
+
+ m_stylesListView->setCurrentIndex( m_stylesListView->model()->index(0,0) );
+ }
+
+FontColorSettingsDialog::~FontColorSettingsDialog()
+ {
+ delete m_styleFactory;
+ }
+
+QHBoxLayout* FontColorSettingsDialog::createBgColorSelector()
+ {
+ m_bgColorSelector = new ColorBox( m_styleFactory->cardBgColor );
+ connect( m_bgColorSelector, SIGNAL(colorChanged(QColor)), SLOT(setBgColor(QColor)) );
+
+ QHBoxLayout* bgColorLt = new QHBoxLayout;
+ bgColorLt->addWidget( new QLabel(tr("Card background color:")) );
+ bgColorLt->addWidget( m_bgColorSelector );
+ bgColorLt->addStretch();
+
+ return bgColorLt;
+ }
+
+QLabel* FontColorSettingsDialog::createStylesList()
+ {
+ QLabel* stylesLbl = new QLabel("<b>"+tr("Field styles")+"</b>");
+
+ QStringList styleNames = FieldStyleFactory::inst()->getStyleNames();
+ StylesListModel* stylesListModel = new StylesListModel( styleNames );
+ m_stylesListView = new QListView;
+ m_stylesListView->setModel( stylesListModel );
+ m_stylesListView->setMaximumWidth( StyleListMaxWidth );
+
+ connect( m_stylesListView->selectionModel(),
+ SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
+ SLOT(updateStyleControls(const QModelIndex&)) );
+
+ return stylesLbl;
+ }
+
+QVBoxLayout* FontColorSettingsDialog::createStyleControls()
+ {
+ m_fontSelector = new QFontComboBox;
+ m_fontSelector->setMaximumWidth( 180 );
+ connect( m_fontSelector, SIGNAL(currentFontChanged(QFont)), SLOT(setFontFamily(QFont)) );
+
+ m_sizeSelector = new QSpinBox;
+ m_sizeSelector->setMaximumWidth( SizeSelectorMaxWidth );
+ m_sizeSelector->setMinimum( 1 );
+ m_sizeSelector->setMaximum( 40 );
+ connect( m_sizeSelector, SIGNAL(valueChanged(int)), SLOT(setFontSize(int)) );
+ QVBoxLayout* styleLt = new QVBoxLayout;
+
+
+ QVBoxLayout* familyLt = new QVBoxLayout;
+ familyLt->addWidget( new QLabel(tr("Font family:")) );
+ familyLt->addWidget( m_fontSelector );
+ QVBoxLayout* sizeLt = new QVBoxLayout;
+ sizeLt->addWidget( new QLabel(tr("Size:")) );
+ sizeLt->addWidget( m_sizeSelector );
+ QHBoxLayout* lt0 = new QHBoxLayout;
+ lt0->setContentsMargins( QMargins() );
+ lt0->addLayout( familyLt );
+ lt0->addLayout( sizeLt );
+ lt0->addStretch();
+
+ m_fontColorSelector = new ColorBox;
+ m_boldCB = new QCheckBox(tr("Bold"));
+ m_italicCB = new QCheckBox(tr("Italic"));
+ QHBoxLayout* lt1 = new QHBoxLayout;
+ lt1->addWidget( new QLabel(tr("Color:")) );
+ lt1->addWidget( m_fontColorSelector );
+ lt1->addWidget( m_boldCB );
+ lt1->addWidget( m_italicCB );
+ lt1->addStretch();
+ connect( m_fontColorSelector, SIGNAL(colorChanged(QColor)), SLOT(setStyleColor(QColor)) );
+ connect( m_boldCB, SIGNAL(stateChanged(int)), SLOT(setBoldFont(int)) );
+ connect( m_italicCB, SIGNAL(stateChanged(int)), SLOT(setItalicFont(int)) );
+
+ m_prefixEdit = new QLineEdit;
+ m_prefixEdit->setMaximumWidth( StyleEditMaxWidth );
+ m_suffixEdit = new QLineEdit;
+ m_suffixEdit->setMaximumWidth( StyleEditMaxWidth );
+ connect( m_prefixEdit, SIGNAL(textChanged(const QString&)), SLOT(setPrefix(const QString)) );
+ connect( m_suffixEdit, SIGNAL(textChanged(const QString&)), SLOT(setSuffix(const QString)) );
+
+ QHBoxLayout* lt2 = new QHBoxLayout;
+ lt2->addWidget( new QLabel(tr("Prefix:")) );
+ lt2->addWidget( m_prefixEdit );
+ lt2->addWidget( new QLabel(tr("Suffix:")) );
+ lt2->addWidget( m_suffixEdit );
+ lt2->addStretch();
+
+ styleLt->addLayout( lt0 );
+ styleLt->addLayout( lt1 );
+ styleLt->addLayout( lt2 );
+ return styleLt;
+ }
+
+void FontColorSettingsDialog::createKeywordBox( QVBoxLayout* aStyleLt )
+ {
+ m_keywordBox = new QGroupBox(tr("Keyword style"));
+ m_keywordBox->setCheckable(true);
+ connect( m_keywordBox, SIGNAL(toggled(bool)), SLOT(setKeywordStyle(bool)) );
+
+ m_keywordColorSelector = new ColorBox();
+ m_keywordBoldCB = new QCheckBox(tr("Bold"));
+ m_keywordItalicCB = new QCheckBox(tr("Italic"));
+ connect( m_keywordBoldCB, SIGNAL(stateChanged(int)), SLOT(setKeywordBoldFont(int)) );
+ connect( m_keywordItalicCB, SIGNAL(stateChanged(int)), SLOT(setKeywordItalicFont(int)) );
+ connect( m_keywordColorSelector, SIGNAL(colorChanged(QColor)), SLOT(setKeywordColor(QColor)) );
+
+ QHBoxLayout* keywordLt1 = new QHBoxLayout;
+ keywordLt1->addWidget( new QLabel(tr("Color:")) );
+ keywordLt1->addWidget( m_keywordColorSelector );
+ keywordLt1->addWidget( m_keywordBoldCB );
+ keywordLt1->addWidget( m_keywordItalicCB );
+ keywordLt1->addStretch();
+
+ m_keywordBox->setLayout( keywordLt1 );
+ aStyleLt->addWidget( m_keywordBox );
+ }
+
+QLabel* FontColorSettingsDialog::createStylePreview()
+ {
+ QLabel* previewLbl = new QLabel("<b>"+tr("Style preview")+"</b>");
+ StylePreviewModel* stylesPreviewModel = new StylePreviewModel( this );
+ m_stylesPreview = new QTableView;
+ m_stylesPreview->setModel( stylesPreviewModel );
+ m_stylesPreview->verticalHeader()->hide();
+ m_stylesPreview->horizontalHeader()->hide();
+ m_stylesPreview->setShowGrid( false );
+ updatePreview();
+ return previewLbl;
+ }
+
+void FontColorSettingsDialog::initData()
+ {
+ m_styleFactory = new FieldStyleFactory( *FieldStyleFactory::inst() );
+ }
+
+void FontColorSettingsDialog::updateStyleControls( const QModelIndex& aIndex )
+{
+ QString styleName = m_styleFactory->getStyleNames().value( aIndex.row() );
+ m_curStyle = m_styleFactory->getStylePtr( styleName );
+
+ m_fontSelector->setCurrentFont( m_curStyle->font );
+ m_sizeSelector->setValue( m_curStyle->font.pointSize() );
+ m_boldCB->setChecked( m_curStyle->font.bold() );
+ m_italicCB->setChecked( m_curStyle->font.italic() );
+ m_fontColorSelector->setColor( m_curStyle->color );
+ m_prefixEdit->setText( m_curStyle->prefix );
+ m_suffixEdit->setText( m_curStyle->suffix );
+
+ // Keyword style
+ m_keywordBox->setChecked(m_curStyle->hasKeyword);
+ m_keywordBoldCB->setChecked( m_curStyle->keywordBold );
+ m_keywordItalicCB->setChecked( m_curStyle->keywordItalic );
+ m_keywordColorSelector->setColor( m_curStyle->keywordColor );
+}
+
+void FontColorSettingsDialog::updatePreview()
+ {
+ m_stylesPreview->reset();
+ m_stylesPreview->resizeColumnsToContents();
+ m_stylesPreview->resizeRowsToContents();
+ }
+
+void FontColorSettingsDialog::setBgColor( QColor aColor )
+ {
+ m_styleFactory->cardBgColor = aColor;
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setFontFamily( QFont aFont )
+ {
+ m_curStyle->font.setFamily( aFont.family() );
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setFontSize( int aSize )
+ {
+ m_curStyle->font.setPointSize( aSize );
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setBoldFont( int aState )
+ {
+ m_curStyle->font.setBold( aState == Qt::Checked );
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setItalicFont( int aState )
+ {
+ m_curStyle->font.setItalic( aState == Qt::Checked );
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setStyleColor( QColor aColor )
+ {
+ m_curStyle->color = aColor;
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setPrefix( const QString aText )
+ {
+ m_curStyle->prefix = aText;
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setSuffix( const QString aText )
+ {
+ m_curStyle->suffix = aText;
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setKeywordStyle( bool aNewKeywordStyleState )
+ {
+ m_curStyle->hasKeyword = aNewKeywordStyleState;
+ if(aNewKeywordStyleState)
+ {
+ m_keywordBoldCB->setChecked(m_curStyle->keywordBold);
+ m_keywordItalicCB->setChecked(m_curStyle->keywordItalic);
+ m_keywordColorSelector->setColor(m_curStyle->keywordColor);
+ }
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setKeywordBoldFont( int aState )
+ {
+ if(!m_curStyle->hasKeyword)
+ return;
+ m_curStyle->keywordBold = (aState == Qt::Checked);
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setKeywordItalicFont( int aState )
+ {
+ if(!m_curStyle->hasKeyword)
+ return;
+ m_curStyle->keywordItalic = (aState == Qt::Checked);
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::setKeywordColor( QColor aColor )
+ {
+ if(!m_curStyle->hasKeyword)
+ return;
+ m_curStyle->keywordColor = aColor;
+ updatePreview();
+ }
+
+void FontColorSettingsDialog::dialogButtonClicked( QAbstractButton* aButton )
+ {
+ if( m_okCancelBox->buttonRole( aButton ) == QDialogButtonBox::ResetRole )
+ {
+ delete m_styleFactory;
+ m_styleFactory = new FieldStyleFactory;
+ m_bgColorSelector->setColor( m_styleFactory->cardBgColor );
+ QModelIndex index = m_stylesListView->model()->index(0,0);
+ m_stylesListView->setCurrentIndex( index );
+ updateStyleControls( index );
+ updatePreview();
+ }
+ }