File indexing completed on 2022-09-27 12:24:15

0001 /*
0002     SPDX-FileCopyrightText: 2006 Carsten Niehaus <cniehaus@kde.org>
0003     SPDX-FileCopyrightText: 2007 Ian Monroe <ian@monroe.nu>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "tablesdialog.h"
0008 
0009 #include <QApplication>
0010 #include <QClipboard>
0011 #include <QContextMenuEvent>
0012 #include <QDialog>
0013 #include <QHeaderView>
0014 #include <QIcon>
0015 #include <QLayout>
0016 #include <QMenu>
0017 
0018 #include <KActionCollection>
0019 #include <KComboBox>
0020 #include <KConfigGroup>
0021 #include <KLocalizedString>
0022 #include <KPageWidgetModel>
0023 #include <KStandardAction>
0024 
0025 TablesDialog::TablesDialog(QWidget *parent)
0026     : KPageDialog(parent)
0027 {
0028     setFaceType(List);
0029 
0030     // setButtons(Help | Close);
0031     // setDefaultButton(Close);
0032 
0033     createGreekSymbolTable();
0034     createNumbersTable();
0035 }
0036 
0037 void TablesDialog::createGreekSymbolTable()
0038 {
0039     auto frame = new QWidget();
0040     KPageWidgetItem *item = addPage(frame, i18n("Greek alphabet"));
0041     item->setHeader(i18n("Greek alphabet"));
0042     item->setIcon(QIcon::fromTheme(QStringLiteral("numbers")));
0043     auto layout = new QVBoxLayout(frame);
0044     layout->setContentsMargins(0, 0, 0, 0);
0045 
0046     QTableWidget *table = new MyTableWidget(frame);
0047     table->verticalHeader()->hide();
0048 
0049     table->setColumnCount(3);
0050     table->setRowCount(24);
0051     table->setHorizontalHeaderLabels(
0052         QStringList() << i18n("Uppercase") << i18n("Lowercase")
0053                       << i18nc("The name of the greek letter in your language. For example 'Alpha' for the first letter. ", "Name"));
0054 
0055     layout->addWidget(table);
0056     table->setItem(0, 0, new MyWidgetItem(QString(QChar(913)))); // capital Alpha
0057     table->setItem(1, 0, new MyWidgetItem(QString(QChar(914))));
0058     table->setItem(2, 0, new MyWidgetItem(QString(QChar(915))));
0059     table->setItem(3, 0, new MyWidgetItem(QString(QChar(916))));
0060     table->setItem(4, 0, new MyWidgetItem(QString(QChar(917))));
0061     table->setItem(5, 0, new MyWidgetItem(QString(QChar(918))));
0062     table->setItem(6, 0, new MyWidgetItem(QString(QChar(919))));
0063     table->setItem(7, 0, new MyWidgetItem(QString(QChar(920))));
0064     table->setItem(8, 0, new MyWidgetItem(QString(QChar(921))));
0065     table->setItem(9, 0, new MyWidgetItem(QString(QChar(922))));
0066     table->setItem(10, 0, new MyWidgetItem(QString(QChar(923))));
0067     table->setItem(11, 0, new MyWidgetItem(QString(QChar(924))));
0068     table->setItem(12, 0, new MyWidgetItem(QString(QChar(925))));
0069     table->setItem(13, 0, new MyWidgetItem(QString(QChar(926))));
0070     table->setItem(14, 0, new MyWidgetItem(QString(QChar(927))));
0071     table->setItem(15, 0, new MyWidgetItem(QString(QChar(928))));
0072     table->setItem(16, 0, new MyWidgetItem(QString(QChar(929))));
0073     table->setItem(17, 0, new MyWidgetItem(QString(QChar(931))));
0074     table->setItem(18, 0, new MyWidgetItem(QString(QChar(932))));
0075     table->setItem(19, 0, new MyWidgetItem(QString(QChar(933))));
0076     table->setItem(20, 0, new MyWidgetItem(QString(QChar(934))));
0077     table->setItem(21, 0, new MyWidgetItem(QString(QChar(935))));
0078     table->setItem(22, 0, new MyWidgetItem(QString(QChar(936))));
0079     table->setItem(23, 0, new MyWidgetItem(QString(QChar(937))));
0080 
0081     // small letters
0082     table->setItem(0, 1, new MyWidgetItem(QString(QChar(945)))); // small alpha
0083     table->setItem(1, 1, new MyWidgetItem(QString(QChar(946))));
0084     table->setItem(2, 1, new MyWidgetItem(QString(QChar(947))));
0085     table->setItem(3, 1, new MyWidgetItem(QString(QChar(948))));
0086     table->setItem(4, 1, new MyWidgetItem(QString(QChar(949))));
0087     table->setItem(5, 1, new MyWidgetItem(QString(QChar(950))));
0088     table->setItem(6, 1, new MyWidgetItem(QString(QChar(951))));
0089     table->setItem(7, 1, new MyWidgetItem(QString(QChar(952))));
0090     table->setItem(8, 1, new MyWidgetItem(QString(QChar(953))));
0091     table->setItem(9, 1, new MyWidgetItem(QString(QChar(954))));
0092     table->setItem(10, 1, new MyWidgetItem(QString(QChar(955))));
0093     table->setItem(11, 1, new MyWidgetItem(QString(QChar(956))));
0094     table->setItem(12, 1, new MyWidgetItem(QString(QChar(957))));
0095     table->setItem(13, 1, new MyWidgetItem(QString(QChar(958))));
0096     table->setItem(14, 1, new MyWidgetItem(QString(QChar(959))));
0097     table->setItem(15, 1, new MyWidgetItem(QString(QChar(960))));
0098     table->setItem(16, 1, new MyWidgetItem(QString(QChar(961))));
0099     // there are two greek letters for sigma
0100     table->setItem(17, 1, new MyWidgetItem(QString(QChar(962)) + ", " + QString(QChar(963))));
0101     table->setItem(18, 1, new MyWidgetItem(QString(QChar(964))));
0102     table->setItem(19, 1, new MyWidgetItem(QString(QChar(965))));
0103     table->setItem(20, 1, new MyWidgetItem(QString(QChar(966))));
0104     table->setItem(21, 1, new MyWidgetItem(QString(QChar(967))));
0105     table->setItem(22, 1, new MyWidgetItem(QString(QChar(968))));
0106     table->setItem(23, 1, new MyWidgetItem(QString(QChar(969))));
0107 
0108     // english names
0109     table->setItem(0, 2, new MyWidgetItem(i18n("alpha")));
0110     table->setItem(1, 2, new MyWidgetItem(i18n("beta")));
0111     table->setItem(2, 2, new MyWidgetItem(i18n("gamma")));
0112     table->setItem(3, 2, new MyWidgetItem(i18n("delta")));
0113     table->setItem(4, 2, new MyWidgetItem(i18n("epsilon")));
0114     table->setItem(5, 2, new MyWidgetItem(i18n("zeta")));
0115     table->setItem(6, 2, new MyWidgetItem(i18n("eta")));
0116     table->setItem(7, 2, new MyWidgetItem(i18n("theta")));
0117     table->setItem(8, 2, new MyWidgetItem(i18n("iota")));
0118     table->setItem(9, 2, new MyWidgetItem(i18n("kappa")));
0119     table->setItem(10, 2, new MyWidgetItem(i18n("lambda")));
0120     table->setItem(11, 2, new MyWidgetItem(i18n("mu")));
0121     table->setItem(12, 2, new MyWidgetItem(i18n("nu")));
0122     table->setItem(13, 2, new MyWidgetItem(i18n("xi")));
0123     table->setItem(14, 2, new MyWidgetItem(i18n("omicron")));
0124     table->setItem(15, 2, new MyWidgetItem(i18n("pi")));
0125     table->setItem(16, 2, new MyWidgetItem(i18n("rho")));
0126     table->setItem(17, 2, new MyWidgetItem(i18n("sigma")));
0127     table->setItem(18, 2, new MyWidgetItem(i18n("tau")));
0128     table->setItem(19, 2, new MyWidgetItem(i18n("upsilon")));
0129     table->setItem(20, 2, new MyWidgetItem(i18n("phi")));
0130     table->setItem(21, 2, new MyWidgetItem(i18n("chi")));
0131     table->setItem(22, 2, new MyWidgetItem(i18n("psi")));
0132     table->setItem(23, 2, new MyWidgetItem(i18n("omega")));
0133 
0134     table->resizeColumnsToContents();
0135     frame->setMinimumWidth(qMax(table->columnWidth(0) + table->columnWidth(1) + table->columnWidth(2), table->horizontalHeader()->sizeHint().width()) + 25);
0136 }
0137 
0138 void TablesDialog::createNumbersTable()
0139 {
0140     auto frame = new QWidget();
0141     KPageWidgetItem *item = addPage(frame, i18n("Numbers"));
0142     item->setHeader(i18n("Numeric Prefixes and Roman Numerals"));
0143     item->setIcon(QIcon::fromTheme(QStringLiteral("numbers")));
0144     auto layout = new QVBoxLayout(frame);
0145     layout->setContentsMargins(0, 0, 0, 0);
0146 
0147     QTableWidget *table = new MyTableWidget(frame);
0148     table->verticalHeader()->hide();
0149 
0150     table->setColumnCount(3);
0151     table->setRowCount(28);
0152     table->setHorizontalHeaderLabels(QStringList() << i18n("Number") << i18nc("For example 'Mono' for 1 and 'Tri' for 3", "Prefix") << i18n("Roman Numerals"));
0153 
0154     layout->addWidget(table);
0155 
0156     table->setItem(0, 0, new MyWidgetItem(i18n("0.5")));
0157     table->setItem(1, 0, new MyWidgetItem(i18n("1")));
0158     table->setItem(2, 0, new MyWidgetItem(i18n("1.5")));
0159     table->setItem(3, 0, new MyWidgetItem(i18n("2")));
0160     table->setItem(4, 0, new MyWidgetItem(i18n("2.5")));
0161     table->setItem(5, 0, new MyWidgetItem(i18n("3")));
0162     table->setItem(6, 0, new MyWidgetItem(i18n("4")));
0163     table->setItem(7, 0, new MyWidgetItem(i18n("5")));
0164     table->setItem(8, 0, new MyWidgetItem(i18n("6")));
0165     table->setItem(9, 0, new MyWidgetItem(i18n("7")));
0166     table->setItem(10, 0, new MyWidgetItem(i18n("8")));
0167     table->setItem(11, 0, new MyWidgetItem(i18n("9")));
0168     table->setItem(12, 0, new MyWidgetItem(i18n("10")));
0169     table->setItem(13, 0, new MyWidgetItem(i18n("11")));
0170     table->setItem(14, 0, new MyWidgetItem(i18n("12")));
0171     table->setItem(15, 0, new MyWidgetItem(i18n("13")));
0172     table->setItem(16, 0, new MyWidgetItem(i18n("14")));
0173     table->setItem(17, 0, new MyWidgetItem(i18n("15")));
0174     table->setItem(18, 0, new MyWidgetItem(i18n("16")));
0175     table->setItem(19, 0, new MyWidgetItem(i18n("17")));
0176     table->setItem(20, 0, new MyWidgetItem(i18n("18")));
0177     table->setItem(21, 0, new MyWidgetItem(i18n("19")));
0178     table->setItem(22, 0, new MyWidgetItem(i18n("20")));
0179     table->setItem(23, 0, new MyWidgetItem(i18n("40")));
0180     table->setItem(24, 0, new MyWidgetItem(i18n("50")));
0181     table->setItem(25, 0, new MyWidgetItem(i18n("60")));
0182     table->setItem(26, 0, new MyWidgetItem(i18n("90")));
0183     table->setItem(27, 0, new MyWidgetItem(i18n("100")));
0184 
0185     // greek names of the numbers
0186     table->setItem(0, 1, new MyWidgetItem(QStringLiteral("hemi")));
0187     table->setItem(1, 1, new MyWidgetItem(QStringLiteral("mono")));
0188     table->setItem(2, 1, new MyWidgetItem(QStringLiteral("sesqui")));
0189     table->setItem(3, 1, new MyWidgetItem(QStringLiteral("di, bi")));
0190     table->setItem(4, 1, new MyWidgetItem(QStringLiteral("hemipenta")));
0191     table->setItem(5, 1, new MyWidgetItem(QStringLiteral("tri")));
0192     table->setItem(6, 1, new MyWidgetItem(QStringLiteral("tetra")));
0193     table->setItem(7, 1, new MyWidgetItem(QStringLiteral("penta")));
0194     table->setItem(8, 1, new MyWidgetItem(QStringLiteral("hexa")));
0195     table->setItem(9, 1, new MyWidgetItem(QStringLiteral("hepta")));
0196     table->setItem(10, 1, new MyWidgetItem(QStringLiteral("octa")));
0197     table->setItem(11, 1, new MyWidgetItem(QStringLiteral("nona, ennea")));
0198     table->setItem(12, 1, new MyWidgetItem(QStringLiteral("deca")));
0199     table->setItem(13, 1, new MyWidgetItem(QStringLiteral("hendeca, undeca")));
0200     table->setItem(14, 1, new MyWidgetItem(QStringLiteral("dodeca")));
0201     table->setItem(15, 1, new MyWidgetItem(QStringLiteral("trideca")));
0202     table->setItem(16, 1, new MyWidgetItem(QStringLiteral("tetradeca")));
0203     table->setItem(17, 1, new MyWidgetItem(QStringLiteral("pentadeca")));
0204     table->setItem(18, 1, new MyWidgetItem(QStringLiteral("hexadeca")));
0205     table->setItem(19, 1, new MyWidgetItem(QStringLiteral("heptadeca")));
0206     table->setItem(20, 1, new MyWidgetItem(QStringLiteral("octadeca")));
0207     table->setItem(21, 1, new MyWidgetItem(QStringLiteral("nonadeca")));
0208     table->setItem(22, 1, new MyWidgetItem(QStringLiteral("eicosa")));
0209     table->setItem(23, 1, new MyWidgetItem(QStringLiteral("tetraconta")));
0210     table->setItem(24, 1, new MyWidgetItem(QStringLiteral("pentaconta")));
0211     table->setItem(25, 1, new MyWidgetItem(QStringLiteral("hexaconta")));
0212     table->setItem(26, 1, new MyWidgetItem(QStringLiteral("nonaconta")));
0213     table->setItem(27, 1, new MyWidgetItem(QStringLiteral("hecta")));
0214 
0215     // roman symbols
0216     table->setItem(1, 2, new MyWidgetItem(QStringLiteral("I")));
0217     table->setItem(3, 2, new MyWidgetItem(QStringLiteral("II")));
0218     table->setItem(5, 2, new MyWidgetItem(QStringLiteral("III")));
0219     table->setItem(6, 2, new MyWidgetItem(QStringLiteral("IV")));
0220     table->setItem(7, 2, new MyWidgetItem(QStringLiteral("V")));
0221     table->setItem(8, 2, new MyWidgetItem(QStringLiteral("VI")));
0222     table->setItem(9, 2, new MyWidgetItem(QStringLiteral("VII")));
0223     table->setItem(10, 2, new MyWidgetItem(QStringLiteral("VIII")));
0224     table->setItem(11, 2, new MyWidgetItem(QStringLiteral("IX")));
0225     table->setItem(12, 2, new MyWidgetItem(QStringLiteral("X")));
0226     table->setItem(13, 2, new MyWidgetItem(QStringLiteral("XI")));
0227     table->setItem(14, 2, new MyWidgetItem(QStringLiteral("XII")));
0228     table->setItem(15, 2, new MyWidgetItem(QStringLiteral("XIII")));
0229     table->setItem(16, 2, new MyWidgetItem(QStringLiteral("XIV")));
0230     table->setItem(17, 2, new MyWidgetItem(QStringLiteral("XV")));
0231     table->setItem(18, 2, new MyWidgetItem(QStringLiteral("XVI")));
0232     table->setItem(19, 2, new MyWidgetItem(QStringLiteral("XVII")));
0233     table->setItem(20, 2, new MyWidgetItem(QStringLiteral("XVIII")));
0234     table->setItem(21, 2, new MyWidgetItem(QStringLiteral("XIV")));
0235     table->setItem(22, 2, new MyWidgetItem(QStringLiteral("XX")));
0236     table->setItem(23, 2, new MyWidgetItem(QStringLiteral("XL")));
0237     table->setItem(24, 2, new MyWidgetItem(QStringLiteral("L")));
0238     table->setItem(25, 2, new MyWidgetItem(QStringLiteral("LX")));
0239     table->setItem(26, 2, new MyWidgetItem(QStringLiteral("XC")));
0240     table->setItem(27, 2, new MyWidgetItem(QStringLiteral("C")));
0241 
0242     table->resizeColumnsToContents();
0243     frame->setMinimumWidth(qMax(table->columnWidth(0) + table->columnWidth(1) + table->columnWidth(2), table->horizontalHeader()->sizeHint().width()) + 25);
0244 }
0245 
0246 TablesDialog::~TablesDialog() = default;
0247 
0248 MyTableWidget::MyTableWidget(QWidget *parent)
0249     : QTableWidget(parent)
0250 {
0251 }
0252 
0253 void MyTableWidget::contextMenuEvent(QContextMenuEvent *event)
0254 {
0255     auto menu = QMenu((QWidget *)sender());
0256     menu.addAction(i18n("&Copy"), this, &MyTableWidget::copyToClipboard, QKeySequence(Qt::Key_C | Qt::CTRL));
0257     menu.exec(event->globalPos());
0258 }
0259 
0260 void MyTableWidget::copyToClipboard()
0261 {
0262     QApplication::clipboard()->setText(currentItem()->data(QTableWidgetItem::Type).toString());
0263 }