-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
181 lines (161 loc) · 6.4 KB
/
mainwindow.cpp
File metadata and controls
181 lines (161 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* This file is part of Ample.
*
* Ample is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ample is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Ample. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QMenu>
#include <QClipboard>
#include <QMimeData>
#include <QFontDatabase>
#include <QString>
#include <QStringList>
#include <QMessageBox>
#include <qmath.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifndef QT_NO_CLIPBOARD
if (const QMimeData *md = QApplication::clipboard()->mimeData())
ui->actionPaste->setEnabled(md->hasText());
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
#endif
#ifdef QT_NO_CLIPBOARD
ui->actionPaste->setEnabled(false);
#endif
ui->actionCopy->setEnabled(false);
ui->actionCut->setEnabled(false);
ui->actionUndo->setEnabled(false);
ui->actionRedo->setEnabled(false);
QActionGroup *alignGroup = new QActionGroup(this);
alignGroup->addAction(ui->actionAlignLeft);
alignGroup->addAction(ui->actionAlignCenter);
alignGroup->addAction(ui->actionAlignRight);
alignGroup->addAction(ui->actionAlignJustify);
alignGroup->setExclusive(true);
connect(alignGroup, SIGNAL(triggered(QAction*)), this, SLOT(textAlignChanged(QAction*)));
activeDocumentsToolButton = new QToolButton(this);
activeDocumentsMenu = new QMenu(this);
activeDocumentsGroup = new QActionGroup(this);
activeDocumentsGroup->setExclusive(true);
ui->actionSwitchDocuments->setMenu(activeDocumentsMenu);
activeDocumentsToolButton->setDefaultAction(ui->actionSwitchDocuments);
activeDocumentsToolButton->setPopupMode(QToolButton::InstantPopup);
ui->mainToolBar->insertWidget(ui->actionRecompute, activeDocumentsToolButton);
recentDocumentsToolButton = new QToolButton(this);
recentDocumentsMenu = new QMenu(this);
recentDocumentsGroup = new QActionGroup(this);
ui->actionOpenRecent->setMenu(recentDocumentsMenu);
recentDocumentsToolButton->setDefaultAction(ui->actionOpenRecent);
recentDocumentsToolButton->setPopupMode(QToolButton::InstantPopup);
ui->mainToolBar->insertWidget(ui->actionNewDocument, recentDocumentsToolButton);
fontFamilyChooser = new QFontComboBox(this);
fontSizeChooser = new QSpinBox(this);
fontChooser = new QWidget(this);
fontChooserLayout = new QGridLayout(fontChooser);
fontChooserLayout->addWidget(fontFamilyChooser, 0, 0, 1, 1);
fontChooserLayout->addWidget(fontSizeChooser, 0, 1, 1, 1);
fontChooserLayout->setHorizontalSpacing(6);
fontChooserLayout->setMargin(0);
ui->textToolBar->insertWidget(ui->actionTextBold, fontChooser);
loadFonts();
CommandIndex *commandIndex = new CommandIndex(this);
CommandIndexDialog *commandIndexDialog = new CommandIndexDialog(commandIndex, this);
commandIndexDialog->show();
commandIndexDialog->raise();
commandIndexDialog->activateWindow();
session = new Session(this);
connect(session, SIGNAL(processingStarted()), this, SLOT(giacProcessingStarted()));
connect(session, SIGNAL(processingFinished(const gen &,const QStringList &)),
this, SLOT(giacProcessingFinished(const gen &,const QStringList &)));
ui->messagesTextBrowser->setFont(QFont("FreeSerif", 12));
ui->messagesTextBrowser->setText(QString("<html><style>radicand{text-decoration:overline;}</style>") +
"<body>Επιστρέφει το μιγαδικό αριθμό ίσο με ∣<i>AC</i>∣⋅∣<i>BD</i>∣⋅∣<i>AD</i>∣<sup>−1</sup>∣<i>BC</i>∣<sup>−1</sup>.</body></html>");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadFonts()
{
QStringList fonts, failed;
fonts << "FreeMono.ttf" << "FreeMonoBold.ttf" << "FreeMonoBoldOblique.ttf" << "FreeMonoOblique.ttf"
<< "FreeSans.ttf" << "FreeSansBold.ttf" << "FreeSansBoldOblique.ttf" << "FreeSansOblique.ttf"
<< "FreeSerif.ttf" << "FreeSerifBold.ttf" << "FreeSerifBoldItalic.ttf" << "FreeSerifItalic.ttf";
foreach (const QString fontName, fonts)
{
QFile res(":/fonts/" + fontName);
if (!res.open(QIODevice::ReadOnly) || QFontDatabase::addApplicationFontFromData(res.readAll()) == -1)
failed.append(fontName);
}
if (!failed.empty())
{
QString message = tr("Failed to load font(s): ") + failed.join(", ");
QMessageBox::warning(this, tr("Font Loading Error"), message);
}
}
void MainWindow::textAlignChanged(QAction *action)
{
if (action == ui->actionAlignLeft) //setAlignment(Qt::AlignLeft | Qt::AlignAbsolute)
;
else if (action == ui->actionAlignCenter) //setAlignment(Qt::AlignHCenter)
;
else if (action == ui->actionAlignRight) //setAlignment(Qt::AlignRight | Qt::AlignAbsolute)
;
else if (action == ui->actionAlignJustify) //setAlignment(Qt::AlignJustify)
;
}
void MainWindow::clipboardDataChanged()
{
#ifndef QT_NO_CLIPBOARD
if (const QMimeData *md = QApplication::clipboard()->mimeData())
ui->actionPaste->setEnabled(md->hasText());
#endif
}
void MainWindow::copyAvailableChanged(bool yes) {
ui->actionCopy->setEnabled(yes);
ui->actionCut->setEnabled(yes);
}
void MainWindow::giacProcessingStarted()
{
ui->messagesTextBrowser->setText("Processing...");
ui->outputLineEdit->clear();
}
gen strToGiac(const QString &str)
{
std::stringstream ss;
gen g;
ss << str.toStdString();
ss >> g;
return g;
}
QString giacToStr(const gen &g)
{
std::stringstream ss;
ss << g;
return ss.str().data();
}
void MainWindow::giacProcessingFinished(const gen &g, const QStringList &messages)
{
ui->outputLineEdit->setText(giacToStr(g));
ui->messagesTextBrowser->setText(messages.join('\n'));
}
void MainWindow::on_evaluateButton_clicked()
{
QString command = ui->inputLineEdit->text();
session->evaluate(strToGiac(command));
}