From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/settings/ColorBox.cpp | 36 ++++ src/settings/ColorBox.h | 28 +++ src/settings/FontColorSettingsDialog.cpp | 300 +++++++++++++++++++++++++++++++ src/settings/FontColorSettingsDialog.h | 71 ++++++++ src/settings/StudySettingsDialog.cpp | 141 +++++++++++++++ src/settings/StudySettingsDialog.h | 45 +++++ src/settings/StylePreviewModel.cpp | 63 +++++++ src/settings/StylePreviewModel.h | 32 ++++ src/settings/StylesListModel.h | 16 ++ 9 files changed, 732 insertions(+) create mode 100644 src/settings/ColorBox.cpp create mode 100644 src/settings/ColorBox.h create mode 100644 src/settings/FontColorSettingsDialog.cpp create mode 100644 src/settings/FontColorSettingsDialog.h create mode 100644 src/settings/StudySettingsDialog.cpp create mode 100644 src/settings/StudySettingsDialog.h create mode 100644 src/settings/StylePreviewModel.cpp create mode 100644 src/settings/StylePreviewModel.h create mode 100644 src/settings/StylesListModel.h (limited to 'src/settings') diff --git a/src/settings/ColorBox.cpp b/src/settings/ColorBox.cpp new file mode 100644 index 0000000..4ed73ab --- /dev/null +++ b/src/settings/ColorBox.cpp @@ -0,0 +1,36 @@ +#include "ColorBox.h" + +ColorBox::ColorBox( QColor aColor ) + { + setAutoFillBackground(true); + setFrameStyle( QFrame::Box ); + setLineWidth(2); + setMinimumHeight( MinHeight ); + setMinimumWidth( MinWidth ); + setColor( aColor ); + } + +void ColorBox::setColor( QColor aColor ) + { + m_color = aColor; + if( isEnabled() ) + setPalette( m_color ); + else + setPalette( Qt::lightGray ); + } + +void ColorBox::mousePressEvent(QMouseEvent* /*event*/) + { + QColor c = QColorDialog::getColor( color(), this ); + if( c.isValid() ) + { + setColor( c ); + emit colorChanged( c ); + } + } + +void ColorBox::changeEvent ( QEvent* event ) + { + if( event->type() == QEvent::EnabledChange ) + setColor( m_color ); + } diff --git a/src/settings/ColorBox.h b/src/settings/ColorBox.h new file mode 100644 index 0000000..5844610 --- /dev/null +++ b/src/settings/ColorBox.h @@ -0,0 +1,28 @@ +#ifndef COLOR_BOX_H +#define COLOR_BOX_H + +#include + +class ColorBox: public QFrame +{ + Q_OBJECT + +public: + ColorBox( QColor aColor = Qt::white ); + QColor color() const { return m_color; } + void setColor( QColor aColor ); + +protected: + void mousePressEvent ( QMouseEvent* event ); + void changeEvent ( QEvent* event ); + +signals: + void colorChanged( QColor aColor ); + +private: + static const int MinHeight = 25; + static const int MinWidth = 50; + QColor m_color; +}; + +#endif 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 + +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(""+tr("Field styles")+""); + + 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(""+tr("Style preview")+""); + 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(); + } + } diff --git a/src/settings/FontColorSettingsDialog.h b/src/settings/FontColorSettingsDialog.h new file mode 100644 index 0000000..273f61c --- /dev/null +++ b/src/settings/FontColorSettingsDialog.h @@ -0,0 +1,71 @@ +#ifndef FONTCOLORSETTINGSDIALOG_H +#define FONTCOLORSETTINGSDIALOG_H + +#include "../field-styles/FieldStyleFactory.h" + +#include + +class ColorBox; + +class FontColorSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + FontColorSettingsDialog(QWidget *parent = 0); + ~FontColorSettingsDialog(); + + const FieldStyleFactory* styleFactory() const { return m_styleFactory; } + +private: + void initData(); + QHBoxLayout* createBgColorSelector(); + QLabel* createStylesList(); + QPushButton* createRestoreButton(); + QVBoxLayout* createStyleControls(); + void createKeywordBox( QVBoxLayout* aStyleLt ); + QLabel* createStylePreview(); + void updatePreview(); + +private slots: + void updateStyleControls( const QModelIndex& aIndex ); + void setBgColor(QColor aColor); + void setFontFamily(QFont aFont); + void setFontSize(int aSize); + void setBoldFont(int aState); + void setItalicFont(int aState); + void setStyleColor(QColor aColor); + void setPrefix(const QString aText); + void setSuffix(const QString aText); + void setKeywordStyle(bool aNewKeywordStyleState); + void setKeywordBoldFont(int aState); + void setKeywordItalicFont(int aState); + void setKeywordColor(QColor aColor); + void dialogButtonClicked( QAbstractButton* aButton ); + +private: + static const int StyleListMaxWidth = 150; + static const int SizeSelectorMaxWidth = 50; + static const int StyleEditMaxWidth = 40; + + FieldStyleFactory* m_styleFactory; + FieldStyle* m_curStyle; + + ColorBox* m_bgColorSelector; + QListView* m_stylesListView; + QFontComboBox* m_fontSelector; + QSpinBox* m_sizeSelector; + QCheckBox* m_boldCB; + QCheckBox* m_italicCB; + ColorBox* m_fontColorSelector; + QLineEdit* m_prefixEdit; + QLineEdit* m_suffixEdit; + QGroupBox* m_keywordBox; + QCheckBox* m_keywordBoldCB; + QCheckBox* m_keywordItalicCB; + ColorBox* m_keywordColorSelector; + QTableView* m_stylesPreview; + QDialogButtonBox* m_okCancelBox; +}; + +#endif diff --git a/src/settings/StudySettingsDialog.cpp b/src/settings/StudySettingsDialog.cpp new file mode 100644 index 0000000..b38bf67 --- /dev/null +++ b/src/settings/StudySettingsDialog.cpp @@ -0,0 +1,141 @@ +#include "StudySettingsDialog.h" + +StudySettingsDialog::StudySettingsDialog(QWidget *parent): + QDialog(parent) + { + initData(); + createUi(); + updateControls(); + } + +void StudySettingsDialog::initData() + { + settings = *StudySettings::inst(); + } + +void StudySettingsDialog::createUi() +{ + createControls(); + setLayout(createMainLayout()); + setWindowTitle(tr("Study settings")); +} + +void StudySettingsDialog::createControls() +{ + dayShiftBox = createSpinBox(0, 12); + newCardsShareBox = createSpinBox(1, 99); + randomnessBox = createSpinBox(1, 99); + cardsDayLimitBox = createSpinBox(1, 500); + newCardsDayLimitBox = createSpinBox(0, 200); + limitForAddingNewCardsBox = createSpinBox(20, 500); + showRandomlyCB = new QCheckBox(tr("Add new cards in random order")); + createButtonBox(); +} + +QSpinBox* StudySettingsDialog::createSpinBox(int min, int max) +{ + QSpinBox* spinBox = new QSpinBox; + spinBox->setMinimum(min); + spinBox->setMaximum(max); + return spinBox; +} + +void StudySettingsDialog::createButtonBox() +{ + buttonBox = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel | + QDialogButtonBox::RestoreDefaults, Qt::Horizontal); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), + SLOT(dialogButtonClicked(QAbstractButton*))); +} + +QBoxLayout* StudySettingsDialog::createMainLayout() +{ + QHBoxLayout* upperPaddedLt = new QHBoxLayout; + upperPaddedLt->addLayout(createUpperLayout()); + upperPaddedLt->addStretch(); + + QVBoxLayout* mainLt = new QVBoxLayout; + mainLt->addLayout(upperPaddedLt); + mainLt->addWidget(showRandomlyCB); + mainLt->addWidget(createLimitsGroup()); + mainLt->addWidget(buttonBox); + return mainLt; +} + +QGridLayout* StudySettingsDialog::createUpperLayout() +{ + QGridLayout* layout = new QGridLayout; + int row = 0; + addUpperGridLine(layout, row++, tr("Day starts at, o'clock:"), dayShiftBox); + addUpperGridLine(layout, row++, tr("Share of new cards:"), newCardsShareBox, "%"); + addUpperGridLine(layout, row++, tr("Repetition interval randomness:"), randomnessBox, "%"); + return layout; +} + +void StudySettingsDialog::addUpperGridLine(QGridLayout* layout, int row, const QString& label, + QWidget* widget, const QString& unitLabel) +{ + QLabel* labelWidget = new QLabel(label); + layout->addWidget(labelWidget, row, 0); + layout->addWidget(widget, row, 1); + layout->addWidget(new QLabel(unitLabel), row, 2); +} + +QGroupBox* StudySettingsDialog::createLimitsGroup() +{ + QGridLayout* layout = new QGridLayout; + layout->setColumnStretch(0, 1); + int row = 0; + addLimitsGridLine(layout, row++, tr("Day reviews limit:"), cardsDayLimitBox); + addLimitsGridLine(layout, row++, tr("Day limit of new cards:"), newCardsDayLimitBox); + addLimitsGridLine(layout, row++, + tr("Don't add new cards after scheduled cards threshold:"), + limitForAddingNewCardsBox); + QGroupBox* group = new QGroupBox(tr("Limits")); + group->setLayout(layout); + return group; +} + +void StudySettingsDialog::addLimitsGridLine(QGridLayout* layout, int row, const QString& label, + QWidget* widget) +{ + QLabel* labelWidget = new QLabel(label); + labelWidget->setWordWrap(true); + layout->addWidget(labelWidget, row, 0); + layout->addWidget(widget, row, 1); +} + +const StudySettings StudySettingsDialog::getSettings() +{ + settings.showRandomly = showRandomlyCB->isChecked(); + settings.newCardsShare = newCardsShareBox->value() / 100.; + settings.schedRandomness = randomnessBox->value() / 100.; + settings.cardsDayLimit = cardsDayLimitBox->value(); + settings.newCardsDayLimit = newCardsDayLimitBox->value(); + settings.limitForAddingNewCards = limitForAddingNewCardsBox->value(); + settings.dayShift = dayShiftBox->value(); + return settings; +} + +void StudySettingsDialog::updateControls() +{ + showRandomlyCB->setChecked( settings.showRandomly ); + newCardsShareBox->setValue( settings.newCardsShare * 100 ); + randomnessBox->setValue( settings.schedRandomness * 100 ); + cardsDayLimitBox->setValue( settings.cardsDayLimit ); + newCardsDayLimitBox->setValue( settings.newCardsDayLimit ); + limitForAddingNewCardsBox->setValue(settings.limitForAddingNewCards); + dayShiftBox->setValue( settings.dayShift ); +} + +void StudySettingsDialog::dialogButtonClicked( QAbstractButton* aButton ) + { + if(buttonBox->buttonRole(aButton) == QDialogButtonBox::ResetRole) + { + settings = StudySettings(); + updateControls(); + } + } diff --git a/src/settings/StudySettingsDialog.h b/src/settings/StudySettingsDialog.h new file mode 100644 index 0000000..121767b --- /dev/null +++ b/src/settings/StudySettingsDialog.h @@ -0,0 +1,45 @@ +#ifndef STUDYSETTINGSDIALOG_H +#define STUDYSETTINGSDIALOG_H + +#include "../study/StudySettings.h" + +#include + +class StudySettingsDialog : public QDialog +{ + Q_OBJECT + +public: + StudySettingsDialog(QWidget *parent = 0); + const StudySettings getSettings(); + +private: + void initData(); + void createUi(); + void updateControls(); + void addUpperGridLine(QGridLayout* layout, int row, const QString& label, QWidget* widget, + const QString& unitLabel = ""); + void addLimitsGridLine(QGridLayout* layout, int row, const QString& label, QWidget* widget); + QSpinBox* createSpinBox(int min, int max); + void createButtonBox(); + void createControls(); + QBoxLayout* createMainLayout(); + QGridLayout*createUpperLayout(); + QGroupBox* createLimitsGroup(); + +private slots: + void dialogButtonClicked( QAbstractButton* aButton ); + +private: + StudySettings settings; + QSpinBox* dayShiftBox; + QCheckBox* showRandomlyCB; + QSpinBox* newCardsShareBox; + QSpinBox* randomnessBox; + QSpinBox* cardsDayLimitBox; + QSpinBox* newCardsDayLimitBox; + QSpinBox* limitForAddingNewCardsBox; + QDialogButtonBox* buttonBox; +}; + +#endif diff --git a/src/settings/StylePreviewModel.cpp b/src/settings/StylePreviewModel.cpp new file mode 100644 index 0000000..e07c809 --- /dev/null +++ b/src/settings/StylePreviewModel.cpp @@ -0,0 +1,63 @@ +#include "StylePreviewModel.h" +#include "../field-styles/FieldStyleFactory.h" + +#include + +QVariant StylePreviewModel::data( const QModelIndex &index, int role ) const + { + if( !index.isValid()) + return QVariant(); + if( index.row() >= rowCount() || index.column() >= columnCount() ) + return QVariant(); + + QString styleName = m_parent->styleFactory()->getStyleNames().value( index.row() ); + FieldStyle fieldStyle = m_parent->styleFactory()->getStyle( styleName ); + switch( index.column() ) + { + case 0: + switch( role ) + { + case Qt::DisplayRole: + return fieldStyle.prefix + styleName + fieldStyle.suffix; + case Qt::FontRole: + return fieldStyle.font; + case Qt::BackgroundRole: + return QBrush( m_parent->styleFactory()->cardBgColor ); + case Qt::ForegroundRole: + return fieldStyle.color; + case Qt::TextAlignmentRole: + return Qt::AlignCenter; + default: + return QVariant(); + } + case 1: + if( fieldStyle.hasKeyword ) + switch( role ) + { + case Qt::DisplayRole: + return tr("keyword"); + case Qt::FontRole: + return fieldStyle.getKeywordStyle().font; + case Qt::BackgroundRole: + return QBrush( m_parent->styleFactory()->cardBgColor ); + case Qt::ForegroundRole: + return fieldStyle.keywordColor; + case Qt::TextAlignmentRole: + return Qt::AlignCenter; + default: + return QVariant(); + } + else + switch( role ) + { + case Qt::DisplayRole: + return QVariant(); + case Qt::BackgroundRole: + return QBrush( m_parent->styleFactory()->cardBgColor ); + default: + return QVariant(); + } + default: + return QVariant(); + } + } diff --git a/src/settings/StylePreviewModel.h b/src/settings/StylePreviewModel.h new file mode 100644 index 0000000..1987431 --- /dev/null +++ b/src/settings/StylePreviewModel.h @@ -0,0 +1,32 @@ +#ifndef STYLESPREVIEWMODEL_H +#define STYLEPREVIEWMODEL_H + +#include "../field-styles/FieldStyleFactory.h" +#include "FontColorSettingsDialog.h" + +#include + +class StylePreviewModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + StylePreviewModel( FontColorSettingsDialog* aParent ): + m_parent( aParent ) + {} + + int rowCount( const QModelIndex& /*parent*/ = QModelIndex() ) const + { return m_parent->styleFactory()->getStyleNames().size(); } + int columnCount( const QModelIndex& /*parent*/ = QModelIndex() ) const + { return 2; } + QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + QVariant headerData( int /*section*/, Qt::Orientation /*orientation*/, int /*role = Qt::DisplayRole*/ ) const + { return QVariant(); } + Qt::ItemFlags flags(const QModelIndex &/*index*/) const {return Qt::NoItemFlags;} + +private: + FontColorSettingsDialog* m_parent; + +}; + +#endif diff --git a/src/settings/StylesListModel.h b/src/settings/StylesListModel.h new file mode 100644 index 0000000..3899ba8 --- /dev/null +++ b/src/settings/StylesListModel.h @@ -0,0 +1,16 @@ +#ifndef STYLESLISTMODEL_H +#define STYLESLISTMODEL_H + +#include + +class StylesListModel: public QStringListModel +{ + Q_OBJECT + +public: + StylesListModel( const QStringList& aStrings ): QStringListModel( aStrings) {} + Qt::ItemFlags flags( const QModelIndex& index ) const + { return QAbstractListModel::flags(index); } +}; + +#endif // STYLESLISTMODEL_H -- cgit