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/dic-options/DictionaryOptionsDialog.cpp | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/dic-options/DictionaryOptionsDialog.cpp (limited to 'src/dic-options/DictionaryOptionsDialog.cpp') diff --git a/src/dic-options/DictionaryOptionsDialog.cpp b/src/dic-options/DictionaryOptionsDialog.cpp new file mode 100644 index 0000000..46bb245 --- /dev/null +++ b/src/dic-options/DictionaryOptionsDialog.cpp @@ -0,0 +1,62 @@ +#include "DictionaryOptionsDialog.h" +#include "../dictionary/CardPack.h" +#include "FieldsPage.h" +#include "PacksPage.h" +#include "FieldsListModel.h" + +DictionaryOptionsDialog::DictionaryOptionsDialog( Dictionary* aDict, QWidget* aParent ): + QDialog( aParent ), m_origDictPtr( aDict ) + { + initData(); + createPages(); + + QDialogButtonBox* okCancelBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal ); + connect( okCancelBox, SIGNAL(accepted()), this, SLOT(accept()) ); + connect( okCancelBox, SIGNAL(rejected()), this, SLOT(reject()) ); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(createDictPathLabel()); + mainLayout->addWidget( m_pages ); + mainLayout->addWidget( okCancelBox ); + setLayout( mainLayout ); + + setWindowTitle( tr("Dictionary options") ); + } + +DictionaryOptionsDialog::~DictionaryOptionsDialog() +{ + delete m_emptyField; +} + +QSize DictionaryOptionsDialog::sizeHint() const +{ + return QSize(700, 400); +} + +QLabel* DictionaryOptionsDialog::createDictPathLabel() +{ + const int MaxPathLength = 500; + QLabel* dictPathLabel = new QLabel; + QFontMetrics metrics(dictPathLabel->font()); + QString dictPath = QDir::toNativeSeparators(m_origDictPtr->getFilePath()); + dictPath = metrics.elidedText(dictPath, Qt::ElideMiddle, MaxPathLength); + dictPathLabel->setText("" + tr("File name") + ": " + dictPath); + return dictPathLabel; +} + +void DictionaryOptionsDialog::initData() + { + m_dict.setDictConfig( m_origDictPtr ); + m_emptyField = new Field(); + m_fieldsListModel = new FieldsListModel( this ); + } + +void DictionaryOptionsDialog::createPages() + { + m_pages = new QTabWidget; + m_pages->addTab( new FieldsPage( this ), QIcon(":/images/fields.png"), tr("Fields") ); + m_pages->addTab( new PacksPage( this ), QIcon(":/images/word-drill.png"), tr("Card packs") ); + } + + -- cgit