forked from uwerat/qwt-mml-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
163 lines (130 loc) · 4.81 KB
/
mainwindow.cpp
File metadata and controls
163 lines (130 loc) · 4.81 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
#include "formulaview.h"
#include "mainwindow.h"
#include <qapplication.h>
#include <qbuffer.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qdebug.h>
#include <qfiledialog.h>
#include <qmimedata.h>
#include <qstatusbar.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
MainWindow::MainWindow()
{
d_view = new FormulaView( this );
setCentralWidget( d_view );
QToolBar *toolBar = new QToolBar( this );
QToolButton *btnLoad = new QToolButton( toolBar );
btnLoad->setText( "Load" );
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
toolBar->addWidget( btnLoad );
QComboBox *comboFontSizes = new QComboBox( toolBar );
QStringList fontSizes;
for ( int i = 8; i <= 128; i += 2 )
fontSizes << QString::number( i );
comboFontSizes->addItems( fontSizes );
comboFontSizes->setCurrentIndex( 32 );
toolBar->addWidget( comboFontSizes );
QCheckBox *checkTransformation = new QCheckBox( toolBar );
checkTransformation->setText( "Transformation" );
checkTransformation->setChecked( true );
toolBar->addWidget( checkTransformation );
d_checkScale = new QCheckBox( toolBar );
d_checkScale->setText( "Scale" );
toolBar->addWidget( d_checkScale );
d_comboRotations = new QComboBox( toolBar );
QStringList rotations;
for ( int i = 0; i <= 360; i += 15 )
rotations << QString::number( i );
d_comboRotations->addItems( rotations );
d_comboRotations->setCurrentIndex( 0 );
toolBar->addWidget( d_comboRotations );
QCheckBox *checkDrawFrames = new QCheckBox( toolBar );
checkDrawFrames->setText( "Draw frames" );
toolBar->addWidget( checkDrawFrames );
QCheckBox *checkColors = new QCheckBox( toolBar );
checkColors->setText( "Colors" );
toolBar->addWidget( checkColors );
addToolBar( toolBar );
connect( btnLoad, SIGNAL( clicked() ), this, SLOT( load() ) );
connect( comboFontSizes, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( updateFontSize( const QString & ) ) );
connect( checkTransformation, SIGNAL( toggled( bool ) ), this, SLOT( updateTransformation( const bool & ) ) );
connect( d_checkScale, SIGNAL( toggled( bool ) ), this, SLOT( updateScaling( const bool & ) ) );
connect( d_comboRotations, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( updateRotation( const QString & ) ) );
connect( checkDrawFrames, SIGNAL( toggled( bool ) ), this, SLOT( updateDrawFrames( const bool & ) ) );
connect( checkColors, SIGNAL( toggled( bool ) ), this, SLOT( updateColors( const bool & ) ) );
updateFontSize( comboFontSizes->currentText() );
updateTransformation( checkTransformation->isChecked() );
updateScaling( d_checkScale->isChecked() );
updateRotation( d_comboRotations->currentText() );
updateDrawFrames( checkDrawFrames->isChecked() );
updateColors( checkColors->isChecked() );
setAcceptDrops(true);
};
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if ( event->mimeData()->urls().count() == 1 )
event->acceptProposedAction();
else
event->ignore();
}
void MainWindow::dragMoveEvent(QDragMoveEvent *event)
{
QString fileName = event->mimeData()->urls().first().toLocalFile();
QFileInfo fileInfo( fileName );
if ( fileInfo.exists() && fileInfo.completeSuffix() == "mml" )
event->acceptProposedAction();
else
event->ignore();
}
void MainWindow::dropEvent(QDropEvent *event)
{
loadFormula( event->mimeData()->urls().first().toLocalFile() );
event->acceptProposedAction();
}
void MainWindow::load()
{
const QString fileName = QFileDialog::getOpenFileName( NULL,
"Load a MathML File", QString::null, "MathML Files (*.mml)" );
if ( !fileName.isEmpty() )
loadFormula( fileName );
else
statusBar()->showMessage( QString::null );
}
void MainWindow::loadFormula( const QString &fileName )
{
statusBar()->showMessage( fileName );
QFile file( fileName );
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
return;
const QByteArray document = file.readAll();
file.close();
d_view->setFormula( document );
}
void MainWindow::updateFontSize( const QString &fontSize )
{
d_view->setFontSize( fontSize.toInt() );
}
void MainWindow::updateTransformation( const bool &transformation )
{
d_checkScale->setEnabled( transformation );
d_comboRotations->setEnabled( transformation );
d_view->setTransformation( transformation );
}
void MainWindow::updateScaling( const bool &scale )
{
d_view->setScale( scale );
}
void MainWindow::updateRotation( const QString &rotation )
{
d_view->setRotation( rotation.toInt() );
}
void MainWindow::updateDrawFrames( const bool &drawFrames )
{
d_view->setDrawFrames( drawFrames );
}
void MainWindow::updateColors( const bool &colors )
{
d_view->setColors( colors );
}