1 | #include "mainwindow.h" |
---|
2 | #include "qpunchcard/card.h" |
---|
3 | #include "qpunchcard/widget.h" |
---|
4 | #include "deckviewer/navigatormodel.h" |
---|
5 | |
---|
6 | #include <QApplication> |
---|
7 | #include <QLabel> |
---|
8 | #include <QtDebug> |
---|
9 | #include <QListView> |
---|
10 | #include <QDockWidget> |
---|
11 | #include <QHBoxLayout> |
---|
12 | #include <QPushButton> |
---|
13 | #include <QMessageBox> |
---|
14 | #include <QFileDialog> |
---|
15 | #include <QFileInfo> |
---|
16 | |
---|
17 | using namespace QPunchCard; |
---|
18 | using namespace App; |
---|
19 | |
---|
20 | |
---|
21 | void MainWindow::window_update_on_file_state(bool opened) { |
---|
22 | // * Window Title setzen |
---|
23 | // * contentsChanged-Signal broadcasten |
---|
24 | // * Menus und Actions erstellen |
---|
25 | if(opened) { |
---|
26 | // titel setzen |
---|
27 | setWindowFilePath(QFileInfo(file).filePath()); |
---|
28 | setWindowTitle(tr("%1[*] - %2").arg( |
---|
29 | file.fileName().isEmpty() ? tr("New Card Deck") : file.fileName() |
---|
30 | ).arg(tr("Punch Card Editor"))); |
---|
31 | // Modified-Stern ([*]) verbinden |
---|
32 | connect(deck, SIGNAL(modified(bool)), this, SLOT(setWindowModified(bool))); |
---|
33 | |
---|
34 | // Broadcasting von "Edited" verbinden |
---|
35 | connect(deck, SIGNAL(contentsChanged(DeckIndex, DeckIndex)), this, SIGNAL(contentsChanged(DeckIndex,DeckIndex))); |
---|
36 | } else { |
---|
37 | setWindowTitle(tr("Punch Card Editor")); |
---|
38 | // passiert folgendes nicht sowieso automatisch? |
---|
39 | disconnect(this, SLOT(setWindowModified(bool))); |
---|
40 | // urhm, den broadcaster... nicht die slots freisetzen, waere bloed. |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void MainWindow::actions_update_on_file_state(bool opened) { |
---|
45 | // 1# |
---|
46 | if(opened) { |
---|
47 | // Actions erstellen |
---|
48 | undo_action = deck->createUndoAction(); |
---|
49 | redo_action = deck->createRedoAction(); |
---|
50 | |
---|
51 | // Undo view |
---|
52 | QDockWidget* undo_view_dock = new QDockWidget(tr("Editing History"), this); |
---|
53 | this->addDockWidget(Qt::RightDockWidgetArea, undo_view_dock); |
---|
54 | undo_view_dock->setVisible(false); |
---|
55 | undo_view_action = undo_view_dock->toggleViewAction(); |
---|
56 | undo_view = new QUndoView(deck->getUndoStack(), undo_view_dock); |
---|
57 | undo_view_dock->setWidget(undo_view); |
---|
58 | |
---|
59 | // Signale verbinden |
---|
60 | connect(deck, SIGNAL(modified(bool)), save_file_action, SLOT(setEnabled(bool))); |
---|
61 | connect(deck, SIGNAL(modified(bool)), save_file_as_action, SLOT(setEnabled(bool))); |
---|
62 | connect(export_picture_action, SIGNAL(triggered()), graphical_editor, SLOT(exportPictureDialog())); |
---|
63 | |
---|
64 | // dynamische Menues und Toolbars erstellen |
---|
65 | createDynamicMenus(); |
---|
66 | createDynamicToolBars(); |
---|
67 | } else { |
---|
68 | // dieser Status existiert gar nicht und so!11 (oh man, aber echt) |
---|
69 | qDebug("Calling bad state in actions_update_on_file_state"); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void MainWindow::createActions() { |
---|
74 | //----------------------- FILE ------------------------------ |
---|
75 | // new File: Always possible, open new Window with empty file |
---|
76 | new_file_action = new QAction(QIcon(":/icons/document-new.png"), tr("&New"), this); |
---|
77 | new_file_action->setShortcuts(QKeySequence::New); |
---|
78 | new_file_action->setStatusTip(tr("Open a new window with an empty card deck")); |
---|
79 | connect(new_file_action, SIGNAL(triggered()), this, SLOT(newFile())); |
---|
80 | |
---|
81 | // open File: Always possible, open file in current window |
---|
82 | open_file_action = new QAction(QIcon(":/icons/document-open.png"), tr("&Open File..."), this); |
---|
83 | open_file_action->setShortcuts(QKeySequence::Open); |
---|
84 | open_file_action->setStatusTip(tr("Open existing card file (any card deck file or text file)")); |
---|
85 | connect(open_file_action, SIGNAL(triggered()), this, SLOT(openFile())); |
---|
86 | |
---|
87 | // save File: Only possible if current deck can be saved |
---|
88 | save_file_action = new QAction(QIcon(":/icons/document-save.png"), tr("&Save File"), this); |
---|
89 | save_file_action->setShortcuts(QKeySequence::Save); |
---|
90 | save_file_action->setStatusTip(tr("Save the current file as card deck")); |
---|
91 | connect(save_file_action, SIGNAL(triggered()), this, SLOT(saveFile())); |
---|
92 | // connection to deck will be etabilshed when deck is loaded |
---|
93 | |
---|
94 | // save File as: Only possible if current deck can be saved |
---|
95 | save_file_as_action = new QAction(QIcon(":/icons/document-save-as.png"), tr("&Save File as..."), this); |
---|
96 | save_file_as_action->setShortcuts(QKeySequence::SaveAs); |
---|
97 | save_file_as_action->setStatusTip(tr("Save the current card deck as another file")); |
---|
98 | connect(save_file_as_action, SIGNAL(triggered()), this, SLOT(saveFileAs())); |
---|
99 | // connection to deck will be etabilshed when deck is loaded |
---|
100 | |
---|
101 | // export Text: Always possible with present deck, deck always present |
---|
102 | export_text_action = new QAction(tr("&Export Text..."), this); |
---|
103 | export_text_action->setStatusTip(tr("Save the decoded plaintext of the current card deck")); |
---|
104 | connect(export_text_action, SIGNAL(triggered()), this, SLOT(exportText())); |
---|
105 | |
---|
106 | // export Picture: Always possible with present deck, deck always present |
---|
107 | export_picture_action = new QAction(tr("&Export Picture of Card..."), this); |
---|
108 | export_picture_action->setStatusTip(tr("Save the visualisation of one or more cards as a picture")); |
---|
109 | // connect to cardeditor will be etabilshed when deck is loaded |
---|
110 | |
---|
111 | // close Window: Always possible. Will close Window and if no more windows left => quitting. |
---|
112 | close_action = new QAction(QIcon(":/icons/system-log-out.png"), tr("&Quit"), this); |
---|
113 | close_action->setShortcuts(QKeySequence::Close); |
---|
114 | close_action->setStatusTip(tr("Close current file while staying in the application")); |
---|
115 | connect(close_action, SIGNAL(triggered()), this, SLOT(close())); |
---|
116 | |
---|
117 | // Display Help: Always possible. |
---|
118 | help_action = new QAction(tr("&Help"), this); |
---|
119 | help_action->setShortcuts(QKeySequence::HelpContents); |
---|
120 | help_action->setStatusTip(tr("Get Help about the usage of this program")); |
---|
121 | connect(help_action, SIGNAL(triggered()), this, SLOT(help())); |
---|
122 | |
---|
123 | // Display about box: Always possible |
---|
124 | about_action = new QAction(tr("&About"), this); |
---|
125 | about_action->setStatusTip(tr("Display some information about the author and program version")); |
---|
126 | connect(about_action, SIGNAL(triggered()), this, SLOT(about())); |
---|
127 | |
---|
128 | //----------------------- EDIT ------------------------------ |
---|
129 | |
---|
130 | |
---|
131 | // Open new Text Editor: Always possible with deck present, deck always present |
---|
132 | new_text_editor_action = new QAction(tr("Open new &Text editor"), this); |
---|
133 | new_text_editor_action->setStatusTip(tr("Display another text editor for editing the dock using a card code")); |
---|
134 | connect(new_text_editor_action, SIGNAL(triggered()), this, SLOT(newTextEditor())); |
---|
135 | |
---|
136 | next_card_action = new QAction(QIcon(":/icons/go-down.png"), tr("&Next Card"), this); |
---|
137 | next_card_action->setStatusTip(tr("Go to next Card")); |
---|
138 | connect(next_card_action, SIGNAL(triggered()), this, SLOT(nextCard())); |
---|
139 | |
---|
140 | prev_card_action = new QAction(QIcon(":/icons/go-up.png"), tr("&Previous Card"), this); |
---|
141 | prev_card_action->setStatusTip(tr("Go to previous Card")); |
---|
142 | connect(prev_card_action, SIGNAL(triggered()), this, SLOT(prevCard())); |
---|
143 | |
---|
144 | new_card_action = new QAction(QIcon(":/icons/list-add.png"), tr("Insert &new Card"), this); |
---|
145 | new_card_action->setStatusTip(tr("Insert new blanco card after current card")); |
---|
146 | connect(new_card_action, SIGNAL(triggered()), this, SLOT(newCard())); |
---|
147 | |
---|
148 | move_forwards_action = new QAction(QIcon(":/icons/format-indent-more.png"), tr("Move forwards"), this); |
---|
149 | move_forwards_action->setStatusTip(tr("Move current card forwards")); |
---|
150 | connect(move_forwards_action, SIGNAL(triggered()), this, SLOT(moveCardForwards())); |
---|
151 | |
---|
152 | move_backwards_action = new QAction(QIcon(":/icons/format-indent-less.png"), tr("Move backwards"), this); |
---|
153 | move_backwards_action->setStatusTip(tr("Move current card backwards")); |
---|
154 | connect(move_backwards_action, SIGNAL(triggered()), this, SLOT(moveCardBackwards())); |
---|
155 | |
---|
156 | // mehr Signale erst beim oeffnen/schliessen einer Datei |
---|
157 | } |
---|
158 | |
---|
159 | void MainWindow::createMenus() { |
---|
160 | file_menu = menuBar()->addMenu(tr("&File")); |
---|
161 | file_menu->addAction(new_file_action); |
---|
162 | file_menu->addSeparator(); |
---|
163 | file_menu->addAction(open_file_action); |
---|
164 | file_menu->addAction(save_file_action); |
---|
165 | file_menu->addAction(save_file_as_action); |
---|
166 | file_menu->addSeparator(); |
---|
167 | file_menu->addAction(export_text_action); |
---|
168 | file_menu->addAction(export_picture_action); |
---|
169 | file_menu->addSeparator(); |
---|
170 | file_menu->addAction(close_action); |
---|
171 | |
---|
172 | // Inhalte von Edit und View erst bei actions_update_on_file_state zugeordnet |
---|
173 | edit_menu = menuBar()->addMenu(tr("&Edit")); |
---|
174 | view_menu = menuBar()->addMenu(tr("&View")); |
---|
175 | |
---|
176 | // Submenus |
---|
177 | toolbars_view_menu = new QMenu("&Toolbars", this); |
---|
178 | docks_view_menu = new QMenu("&Docks", this); |
---|
179 | |
---|
180 | devices_menu = menuBar()->addMenu(tr("&Devices")); |
---|
181 | // hier alle Geraete auflisten, fuer die es Treiber gibt (=> driver, DriverOverview oder so) |
---|
182 | // wird von createDevices() gemacht |
---|
183 | |
---|
184 | menuBar()->addSeparator(); // for Motif ;-) |
---|
185 | help_menu = menuBar()->addMenu(tr("&Help")); |
---|
186 | help_menu->addAction(help_action); |
---|
187 | help_menu->addSeparator(); |
---|
188 | help_menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); |
---|
189 | help_menu->addAction(about_action); |
---|
190 | } |
---|
191 | |
---|
192 | void MainWindow::createDynamicMenus() { |
---|
193 | // nur von actions_update_on_file_state aufzurufen. |
---|
194 | edit_menu->clear(); |
---|
195 | edit_menu->addAction(undo_action); |
---|
196 | edit_menu->addAction(redo_action); |
---|
197 | edit_menu->addAction(undo_view_action); |
---|
198 | edit_menu->addSeparator(); |
---|
199 | // Cut, Copy, Insert => Waere ziemlich kompliziert wegen der vielen Modelle |
---|
200 | edit_menu->addAction(new_card_action); |
---|
201 | edit_menu->addAction(move_backwards_action); |
---|
202 | edit_menu->addAction(move_forwards_action); |
---|
203 | |
---|
204 | view_menu->clear(); |
---|
205 | view_menu->addAction(new_text_editor_action); |
---|
206 | view_menu->addSeparator(); |
---|
207 | // hier jetzt actions von der EditorKomponente |
---|
208 | // (Zoom, usw.) |
---|
209 | view_menu->addSeparator(); |
---|
210 | view_menu->addMenu(toolbars_view_menu); |
---|
211 | view_menu->addMenu(docks_view_menu); |
---|
212 | // Ansichten: |
---|
213 | // - Neue Textansicht hinzufuegen |
---|
214 | // - Eigenschaften der Lochkarten-Ansicht hinzufuegen |
---|
215 | // - Visualisierungsansicht aendern und so (Qualitaet) |
---|
216 | // Navigation |
---|
217 | // - Vor/Zurueck bei Lochkarte oder Spalte (letzteres doof) |
---|
218 | |
---|
219 | |
---|
220 | } |
---|
221 | |
---|
222 | void MainWindow::createToolBars() { |
---|
223 | main_bar = addToolBar(tr("Main")); |
---|
224 | toolbars_view_menu->addAction(main_bar->toggleViewAction()); |
---|
225 | |
---|
226 | main_bar->addAction(new_file_action); |
---|
227 | main_bar->addAction(open_file_action); |
---|
228 | main_bar->addSeparator(); |
---|
229 | main_bar->addAction(save_file_action); |
---|
230 | main_bar->addAction(save_file_as_action); |
---|
231 | main_bar->addSeparator(); |
---|
232 | main_bar->addAction(export_text_action); |
---|
233 | // usw. |
---|
234 | |
---|
235 | navi_bar = addToolBar(tr("Navigation")); |
---|
236 | toolbars_view_menu->addAction(navi_bar->toggleViewAction()); |
---|
237 | |
---|
238 | navi_bar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
---|
239 | navi_bar->addAction(prev_card_action); |
---|
240 | navi_bar->addAction(next_card_action); |
---|
241 | navi_bar->addAction(new_card_action); |
---|
242 | navi_bar->addAction(this->move_backwards_action); |
---|
243 | navi_bar->addAction(this->move_forwards_action); |
---|
244 | } |
---|
245 | |
---|
246 | void MainWindow::createDynamicToolBars() { |
---|
247 | // hier halt sowas wie undo, redo, usw. |
---|
248 | // eigentlich brauchen wir auch nur eine Toolbar... |
---|
249 | } |
---|