ThemeManager::ThemeManager(QSettings& settings, QWidget* parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), m_settings(settings) { setWindowTitle(tr("Themes")); m_tabs = new QTabWidget(this); // Find view sizes int focush = style()->pixelMetric(QStyle::PM_FocusFrameHMargin); int focusv = style()->pixelMetric(QStyle::PM_FocusFrameVMargin); int frame = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); int scrollbar = style()->pixelMetric(QStyle::PM_SliderThickness); QSize grid_size(259 + focush, 154 + focusv + (fontMetrics().height() * 2)); QSize view_size((grid_size.width() + frame + focush) * 2 + scrollbar, (grid_size.height() + frame + focusv) * 2); // Add default themes tab QWidget* tab = new QWidget(this); m_tabs->addTab(tab, tr("Default")); // Add default themes list m_default_themes = new QListWidget(tab); m_default_themes->setSortingEnabled(true); m_default_themes->setViewMode(QListView::IconMode); m_default_themes->setIconSize(QSize(258, 153)); m_default_themes->setGridSize(grid_size); m_default_themes->setMovement(QListView::Static); m_default_themes->setResizeMode(QListView::Adjust); m_default_themes->setSelectionMode(QAbstractItemView::SingleSelection); m_default_themes->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_default_themes->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_default_themes->setMinimumSize(view_size); m_default_themes->setWordWrap(true); addItem("gentleblues", true, tr("Gentle Blues")); addItem("oldschool", true, tr("Old School")); addItem("spacedreams", true, tr("Space Dreams")); addItem("writingdesk", true, tr("Writing Desk")); // Add default control buttons QPushButton* new_default_button = new QPushButton(tr("New"), tab); new_default_button->setAutoDefault(false); connect(new_default_button, SIGNAL(clicked()), this, SLOT(newTheme())); m_clone_default_button = new QPushButton(tr("Duplicate"), tab); m_clone_default_button->setAutoDefault(false); connect(m_clone_default_button, SIGNAL(clicked()), this, SLOT(cloneTheme())); // Lay out default themes tab QGridLayout* default_layout = new QGridLayout(tab); default_layout->setColumnStretch(0, 1); default_layout->setRowStretch(2, 1); default_layout->addWidget(m_default_themes, 0, 0, 3, 1); default_layout->addWidget(new_default_button, 0, 1); default_layout->addWidget(m_clone_default_button, 1, 1); // Add themes tab tab = new QWidget(this); m_tabs->addTab(tab, tr("Custom")); // Add themes list m_themes = new QListWidget(tab); m_themes->setSortingEnabled(true); m_themes->setViewMode(QListView::IconMode); m_themes->setIconSize(QSize(258, 153)); m_themes->setGridSize(grid_size); m_themes->setMovement(QListView::Static); m_themes->setResizeMode(QListView::Adjust); m_themes->setSelectionMode(QAbstractItemView::SingleSelection); m_themes->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_themes->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_themes->setMinimumSize(view_size); m_themes->setWordWrap(true); QDir dir(Theme::path(), "*.theme"); QStringList themes = dir.entryList(QDir::Files, QDir::Name | QDir::IgnoreCase); for (const QString& theme : themes) { QString name = QSettings(dir.filePath(theme), QSettings::IniFormat).value("Name").toString(); if (!name.isEmpty()) { addItem(QFileInfo(theme).completeBaseName(), false, name); } else { name = QUrl::fromPercentEncoding(QFileInfo(theme).completeBaseName().toUtf8()); QSettings(dir.filePath(theme), QSettings::IniFormat).setValue("Name", name); QString id = Theme::createId(); dir.rename(theme, id + ".theme"); dir.remove(QFileInfo(theme).completeBaseName() + ".png"); QStringList sessions = QDir(Session::path(), "*.session").entryList(QDir::Files); sessions.prepend(""); for (const QString& file : sessions) { Session session(file); if ((session.theme() == name) && (session.themeDefault() == false)) { session.setTheme(id, false); } } addItem(id, false, name); } } // Add control buttons QPushButton* new_button = new QPushButton(tr("New"), tab); new_button->setAutoDefault(false); connect(new_button, SIGNAL(clicked()), this, SLOT(newTheme())); m_clone_button = new QPushButton(tr("Duplicate"), tab); m_clone_button->setAutoDefault(false); m_clone_button->setEnabled(false); connect(m_clone_button, SIGNAL(clicked()), this, SLOT(cloneTheme())); m_edit_button = new QPushButton(tr("Edit"), tab); m_edit_button->setAutoDefault(false); m_edit_button->setEnabled(false); connect(m_edit_button, SIGNAL(clicked()), this, SLOT(editTheme())); m_remove_button = new QPushButton(tr("Delete"), tab); m_remove_button->setAutoDefault(false); m_remove_button->setEnabled(false); connect(m_remove_button, SIGNAL(clicked()), this, SLOT(deleteTheme())); QPushButton* import_button = new QPushButton(tr("Import"), tab); import_button->setAutoDefault(false); connect(import_button, SIGNAL(clicked()), this, SLOT(importTheme())); m_export_button = new QPushButton(tr("Export"), tab); m_export_button->setAutoDefault(false); m_export_button->setEnabled(false); connect(m_export_button, SIGNAL(clicked()), this, SLOT(exportTheme())); // Lay out custom themes tab QGridLayout* custom_layout = new QGridLayout(tab); custom_layout->setColumnStretch(0, 1); custom_layout->setRowMinimumHeight(4, import_button->sizeHint().height()); custom_layout->setRowStretch(7, 1); custom_layout->addWidget(m_themes, 0, 0, 8, 1); custom_layout->addWidget(new_button, 0, 1); custom_layout->addWidget(m_clone_button, 1, 1); custom_layout->addWidget(m_edit_button, 2, 1); custom_layout->addWidget(m_remove_button, 3, 1); custom_layout->addWidget(import_button, 5, 1); custom_layout->addWidget(m_export_button, 6, 1); // Lay out dialog QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_tabs, 1); layout->addSpacing(layout->margin()); layout->addWidget(buttons); // Select theme QString theme = m_settings.value("ThemeManager/Theme").toString(); bool is_default = m_settings.value("ThemeManager/ThemeDefault", false).toBool(); if (!selectItem(theme, is_default)) { selectItem(Theme::defaultId(), true); } selectionChanged(is_default); connect(m_default_themes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentThemeChanged(QListWidgetItem*))); connect(m_themes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentThemeChanged(QListWidgetItem*))); connect(m_themes, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(editTheme())); // Restore size resize(m_settings.value("ThemeManager/Size", sizeHint()).toSize()); }
PreferencesDialog::PreferencesDialog(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f), ui(new Ui::PreferencesDialogBox()) { ui->setupUi(this); NewEmptyMapDialog dialog; ui->m_defaultMapModeCombo->addItems(dialog.getPermissionData()); m_preferences = PreferencesManager::getInstance(); m_aliasModel = new DiceAliasModel(); ui->m_tableViewAlias->setModel(m_aliasModel); m_diceParser = new DiceParser(); m_aliasModel->setAliases(m_diceParser->getAliases()); QHeaderView* horizontalHeader = ui->m_tableViewAlias->horizontalHeader(); horizontalHeader->setSectionResizeMode(DiceAliasModel::PATTERN,QHeaderView::ResizeToContents); horizontalHeader->setSectionResizeMode(DiceAliasModel::VALUE,QHeaderView::Stretch); horizontalHeader->setSectionResizeMode(DiceAliasModel::METHOD,QHeaderView::ResizeToContents); ui->m_tableViewAlias->setItemDelegateForColumn(DiceAliasModel::METHOD,new CheckBoxDelegate()); m_paletteModel = new PaletteModel(); m_paletteModel->setPalette(palette()); ui->m_paletteTableView->setModel(m_paletteModel); horizontalHeader = ui->m_paletteTableView->horizontalHeader(); horizontalHeader->setSectionResizeMode(0,QHeaderView::Stretch); connect(this, SIGNAL(accepted()), this, SLOT(save())); connect(ui->m_startDiag,SIGNAL(clicked()),this,SLOT(performDiag())); //ui->m_fogColor->setTransparency(true); //set general panel as default. ui->tabWidget->setCurrentIndex(0); //aliases connect(ui->m_addDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_delDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_upDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_downDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_topDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_bottomDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction())); connect(ui->m_testPushButton,SIGNAL(clicked()),this,SLOT(testAliasCommand())); // Misc setSizeGripEnabled(true); setWindowTitle(QString("%1 - %2").arg(m_preferences->value("Application_Name","rolisteam").toString(),tr("Preferences"))); setWindowModality(Qt::ApplicationModal); m_preferences->registerListener("isPlayer",m_aliasModel); m_aliasModel->setGM(!m_preferences->value("isPlayer",false).toBool()); // background connect(ui->m_positioningComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(applyBackground())); connect(ui->m_bgColorPush, SIGNAL(colorChanged(QColor)), this, SLOT(applyBackground())); connect(ui->m_backgroundImage,SIGNAL(pathChanged()),this,SLOT(applyBackground())); //themes connect(ui->m_copyThemeButton,SIGNAL(clicked()),this,SLOT(dupplicateTheme())); connect(ui->m_themeNameLineEdit,SIGNAL(textEdited(QString)),this,SLOT(setTitleAtCurrentTheme())); connect(ui->m_paletteTableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(editColor(QModelIndex))); connect(ui->m_cssEdit,SIGNAL(clicked()),this,SLOT(editCss())); connect(ui->m_exportBtn,SIGNAL(clicked()),this,SLOT(exportTheme())); connect(ui->m_importBtn,SIGNAL(clicked()),this,SLOT(importTheme())); connect(ui->m_deleteTheme,SIGNAL(clicked()),this,SLOT(deleteTheme())); }