Warning, file /graphics/kxstitch/src/SymbolSelectorDlg.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 2012-2015 by Stephen Allewell 0003 * steve.allewell@gmail.com 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 */ 0010 0011 /** 0012 * @file 0013 * Implement the SymbolSelectorDlg class. 0014 */ 0015 0016 /** 0017 * @page symbolSelectorDlg Symbol Selector Dialog 0018 * This dialog allows the user to select a symbol to be associated with a 0019 * DocumentFloss. Any currently used flosses are shown grayed out and are 0020 * not selectable. The selection of a new symbol is made by clicking on the 0021 * required symbol, depending on the system settings for KDE, this will 0022 * require a single or double click. 0023 */ 0024 0025 #include "SymbolSelectorDlg.h" 0026 0027 #include <QListWidget> 0028 0029 #include <KHelpClient> 0030 #include <KLocalizedString> 0031 0032 #include "Symbol.h" 0033 #include "SymbolLibrary.h" 0034 #include "SymbolManager.h" 0035 #include "configuration.h" 0036 0037 /** 0038 * Constructor. 0039 * 0040 * @param parent a pointer to a QWidget parent object 0041 * @param symbolLibrary the name of the symbol library to use 0042 */ 0043 SymbolSelectorDlg::SymbolSelectorDlg(QWidget *parent, const QString &symbolLibrary) 0044 : QDialog(parent) 0045 { 0046 setWindowTitle(i18n("Symbol Selector")); 0047 ui.setupUi(this); 0048 0049 SymbolLibrary *library = SymbolManager::library(symbolLibrary); 0050 0051 if (library == nullptr) { 0052 library = SymbolManager::library(QStringLiteral("kxstitch")); 0053 } 0054 0055 ui.SymbolTable->loadFromLibrary(library); 0056 } 0057 0058 /** 0059 * Set the current symbol and the used symbols to correctly display the 0060 * symbols from the library. 0061 * 0062 * @param symbol the current symbol index 0063 * @param used a const reference to a QList representing the indexes of used symbols 0064 */ 0065 void SymbolSelectorDlg::setSelectedSymbol(qint16 symbol, const QList<qint16> &used) 0066 { 0067 m_currentSymbol = symbol; 0068 m_usedSymbols = used; 0069 0070 foreach (qint16 index, m_usedSymbols) { 0071 ui.SymbolTable->disableItem(index); 0072 } 0073 0074 ui.SymbolTable->setCurrent(m_currentSymbol); 0075 } 0076 0077 /** 0078 * Get the selected symbol. 0079 * 0080 * @return a qint16 representing the selected symbol 0081 */ 0082 qint16 SymbolSelectorDlg::selectedSymbol() 0083 { 0084 return m_currentSymbol; 0085 } 0086 0087 /** 0088 * Override hideEvent to save the dialogs size. 0089 * 0090 * @param event a pointer to a QHideEvent 0091 */ 0092 void SymbolSelectorDlg::hideEvent(QHideEvent *event) 0093 { 0094 KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).writeEntry(QStringLiteral("SymbolSelectorDlg"), size()); 0095 0096 QDialog::hideEvent(event); 0097 } 0098 0099 /** 0100 * Override showEvent to restore the dialogs size. 0101 * 0102 * @param event a pointer to a QShowEvent 0103 */ 0104 void SymbolSelectorDlg::showEvent(QShowEvent *event) 0105 { 0106 QDialog::showEvent(event); 0107 0108 if (KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).hasKey(QStringLiteral("SymbolSelectorDlg"))) { 0109 resize(KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).readEntry(QStringLiteral("SymbolSelectorDlg"), QSize())); 0110 } 0111 } 0112 0113 /** 0114 * Set the selected symbol from the selected icon. 0115 * This slot is connected to the SymbolListWidget executed signal. 0116 * The index is stored as a data item in the QListWidgetItem. 0117 * 0118 * @param item a pointer to the QListWidgetItem that was selected 0119 */ 0120 void SymbolSelectorDlg::on_SymbolTable_itemClicked(QListWidgetItem *item) 0121 { 0122 if (item->flags() & Qt::ItemIsEnabled) { 0123 m_usedSymbols.removeOne(m_currentSymbol); 0124 ui.SymbolTable->enableItem(m_currentSymbol); 0125 m_currentSymbol = static_cast<qint16>(item->data(Qt::UserRole).toInt()); 0126 ui.SymbolTable->disableItem(m_currentSymbol); 0127 m_usedSymbols.append(m_currentSymbol); 0128 accept(); 0129 } 0130 } 0131 0132 /** 0133 * Called when the dialog Close button is pressed. 0134 */ 0135 void SymbolSelectorDlg::on_DialogButtonBox_rejected() 0136 { 0137 reject(); 0138 } 0139 0140 /** 0141 * Called when the dialog Help button is pressed. 0142 */ 0143 void SymbolSelectorDlg::on_DialogButtonBox_helpRequested() 0144 { 0145 KHelpClient::invokeHelp(QStringLiteral("SymbolSelectorDialog"), QStringLiteral("kxstitch")); 0146 } 0147 0148 #include "moc_SymbolSelectorDlg.cpp"