source: projects/punch-card/punch-card-editor/src/app/mainwindow.ui.cc @ 53

Last change on this file since 53 was 53, checked in by sven, 14 years ago

Punch Card Editor, ongoing development

  • Extended new Deck interface, expanding the undo framework
  • Implemented editor changes via undo framework
  • revised the menu and toolbar actions and structure (now dynamic construction at deck load time), implemented undo viewer
  • Started implementation of device driver framework in menu
  • Embedded the Qextserialport library (http://qextserialport.sourceforge.net/)
  • Started the Documation M200 Client device driver (well, just created the directory structure and qmake project file infrastructure)
  • At the current state, the complete project compiles :-)

Statistics: About 3500 Lines of code (without libqextserialport)

-- sven @ workstation

File size: 9.7 KB
RevLine 
[52]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
17using namespace QPunchCard;
18using namespace App;
19
[53]20
21void 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
44void 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
63                // dynamische Menues und Toolbars erstellen
64                createDynamicMenus();
65                createDynamicToolBars();
66        } else {
67                // dieser Status existiert gar nicht und so!11 (oh man, aber echt)
68                qDebug("Calling bad state in actions_update_on_file_state");
69        }
70}
71
[52]72void MainWindow::createActions() {
[53]73        //----------------------- FILE ------------------------------
74        // new File: Always possible, open new Window with empty file
75        new_file_action = new QAction(tr("&New"), this);
[52]76        new_file_action->setShortcuts(QKeySequence::New);
[53]77        new_file_action->setStatusTip(tr("Open a new window with an empty card deck"));
[52]78        connect(new_file_action, SIGNAL(triggered()), this, SLOT(newFile()));
79
[53]80        // open File: Always possible, open file in current window
[52]81        open_file_action = new QAction(tr("&Open File..."), this);
82        open_file_action->setShortcuts(QKeySequence::Open);
83        open_file_action->setStatusTip(tr("Open existing card file (any card deck file or text file)"));
84        connect(open_file_action, SIGNAL(triggered()), this, SLOT(openFile()));
85
[53]86        // save File: Only possible if current deck can be saved
[52]87        save_file_action = new QAction(tr("&Save File"), this);
88        save_file_action->setShortcuts(QKeySequence::Save);
89        save_file_action->setStatusTip(tr("Save the current file as card deck"));
90        connect(save_file_action, SIGNAL(triggered()), this, SLOT(saveFile()));
[53]91        // connection to deck will be etabilshed when deck is loaded
[52]92
[53]93        // save File as: Only possible if current deck can be saved
[52]94        save_file_as_action = new QAction(tr("&Save File as..."), this);
95        save_file_as_action->setShortcuts(QKeySequence::SaveAs);
96        save_file_as_action->setStatusTip(tr("Save the current card deck as another file"));
97        connect(save_file_as_action, SIGNAL(triggered()), this, SLOT(saveFileAs()));
[53]98        // connection to deck will be etabilshed when deck is loaded
[52]99
[53]100        // export Text: Always possible with present deck, deck always present
[52]101        export_text_action = new QAction(tr("&Export Text..."), this);
102        export_text_action->setStatusTip(tr("Save the decoded plaintext of the current card deck"));
103        connect(export_text_action, SIGNAL(triggered()), this, SLOT(exportText()));
104
[53]105        // export Picture: Always possible with present deck, deck always present
[52]106        export_picture_action = new QAction(tr("&Export Picture of Card..."), this);
107        export_picture_action->setStatusTip(tr("Save the visualisation of one or more cards as a picture"));
108        connect(export_picture_action, SIGNAL(triggered()), this, SLOT(exportPicture()));
109
[53]110        // close Window: Always possible. Will close Window and if no more windows left => quitting.
111        close_action = new QAction(tr("&Quit"), this);
112        close_action->setShortcuts(QKeySequence::Close);
113        close_action->setStatusTip(tr("Close current file while staying in the application"));
114        connect(close_action, SIGNAL(triggered()), this, SLOT(close()));
[52]115
[53]116        // Display Help: Always possible.
[52]117        help_action = new QAction(tr("&Help"), this);
[53]118        help_action->setShortcuts(QKeySequence::HelpContents);
[52]119        help_action->setStatusTip(tr("Get Help about the usage of this program"));
120        connect(help_action, SIGNAL(triggered()), this, SLOT(help()));
121
[53]122        // Display about box: Always possible
[52]123        about_action = new QAction(tr("&About"), this);
124        about_action->setStatusTip(tr("Display some information about the author and program version"));
125        connect(about_action, SIGNAL(triggered()), this, SLOT(about()));
126
[53]127        //----------------------- EDIT ------------------------------
128
129
130        // Open new Text Editor: Always possible with deck present, deck always present
[52]131        new_text_editor_action = new QAction(tr("Open new &Text editor"), this);
132        new_text_editor_action->setStatusTip(tr("Display another text editor for editing the dock using a card code"));
133        connect(new_text_editor_action, SIGNAL(triggered()), this, SLOT(newTextEditor()));
134
135        next_card_action = new QAction(tr("&Next Card"), this);
136        next_card_action->setStatusTip(tr("Go to next Card"));
137        connect(next_card_action, SIGNAL(triggered()), this, SLOT(nextCard()));
138
139        prev_card_action = new QAction(tr("&Previous Card"), this);
140        prev_card_action->setStatusTip(tr("Go to previous Card"));
141        connect(prev_card_action, SIGNAL(triggered()), this, SLOT(prevCard()));
142
143        new_card_action = new QAction(tr("Insert &new Card"), this);
144        new_card_action->setStatusTip(tr("Insert new blanco card after current card"));
145        connect(new_card_action, SIGNAL(triggered()), this, SLOT(newCard()));
146
147        move_forwards_action = new QAction(tr("Move forwards"), this);
148        move_forwards_action->setStatusTip(tr("Move current card forwards"));
149        connect(move_forwards_action, SIGNAL(triggered()), this, SLOT(moveCardForwards()));
150
151        move_backwards_action = new QAction(tr("Move backwards"), this);
152        move_backwards_action->setStatusTip(tr("Move current card backwards"));
153        connect(move_backwards_action, SIGNAL(triggered()), this, SLOT(moveCardBackwards()));
154
155        // mehr Signale erst beim oeffnen/schliessen einer Datei
156}
157
158void MainWindow::createMenus() {
159        file_menu = menuBar()->addMenu(tr("&File"));
160        file_menu->addAction(new_file_action);
161        file_menu->addSeparator();
162        file_menu->addAction(open_file_action);
163        file_menu->addAction(save_file_action);
164        file_menu->addAction(save_file_as_action);
165        file_menu->addSeparator();
166        file_menu->addAction(export_text_action);
167        file_menu->addAction(export_picture_action);
168        file_menu->addSeparator();
[53]169        file_menu->addAction(close_action);
[52]170
[53]171        // Inhalte von Edit und View erst bei actions_update_on_file_state zugeordnet
[52]172        edit_menu = menuBar()->addMenu(tr("&Edit"));
[53]173        view_menu = menuBar()->addMenu(tr("&View"));
174
175        // Submenus
176        toolbars_view_menu = new QMenu("&Toolbars", this);
177        docks_view_menu = new QMenu("&Docks", this);
178
179        devices_menu = menuBar()->addMenu(tr("&Devices"));
180        // hier alle Geraete auflisten, fuer die es Treiber gibt (=> driver, DriverOverview oder so)
181        // wird von createDevices() gemacht
182
183        menuBar()->addSeparator(); // for Motif ;-)
184        help_menu = menuBar()->addMenu(tr("&Help"));
185        help_menu->addAction(help_action);
186        help_menu->addSeparator();
187        help_menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
188        help_menu->addAction(about_action);
189}
190
191void MainWindow::createDynamicMenus() {
192        // nur von actions_update_on_file_state aufzurufen.
193        edit_menu->clear();
[52]194        edit_menu->addAction(undo_action);
195        edit_menu->addAction(redo_action);
[53]196        edit_menu->addAction(undo_view_action);
[52]197        edit_menu->addSeparator();
[53]198        // Cut, Copy, Insert => Waere ziemlich kompliziert wegen der vielen Modelle
199        edit_menu->addAction(new_card_action);
200        edit_menu->addAction(move_backwards_action);
201        edit_menu->addAction(move_forwards_action);
[52]202
[53]203        view_menu->clear();
[52]204        view_menu->addAction(new_text_editor_action);
205        view_menu->addSeparator();
[53]206        // hier jetzt actions von der EditorKomponente
207        // (Zoom, usw.)
208        view_menu->addSeparator();
209        view_menu->addMenu(toolbars_view_menu);
210        view_menu->addMenu(docks_view_menu);
[52]211        // Ansichten:
212        // - Neue Textansicht hinzufuegen
213        // - Eigenschaften der Lochkarten-Ansicht hinzufuegen
214        // - Visualisierungsansicht aendern und so (Qualitaet)
215        // Navigation
216        // - Vor/Zurueck bei Lochkarte oder Spalte (letzteres doof)
217
218
219}
220
221void MainWindow::createToolBars() {
[53]222        main_bar = addToolBar(tr("Main"));
223        toolbars_view_menu->addAction(main_bar->toggleViewAction());
[52]224
[53]225        main_bar->addAction(new_file_action);
226        main_bar->addAction(open_file_action);
227        main_bar->addSeparator();
228        main_bar->addAction(save_file_action);
229        main_bar->addAction(save_file_as_action);
230        main_bar->addSeparator();
231        main_bar->addAction(export_text_action);
232        // usw.
233
[52]234        navi_bar = addToolBar(tr("Navigation"));
[53]235        toolbars_view_menu->addAction(navi_bar->toggleViewAction());
236
[52]237        navi_bar->addAction(prev_card_action);
238        navi_bar->addAction(next_card_action);
239        navi_bar->addAction(new_card_action);
240        navi_bar->addAction(this->move_backwards_action);
241        navi_bar->addAction(this->move_forwards_action);
242}
[53]243
244void MainWindow::createDynamicToolBars() {
245        // hier halt sowas wie undo, redo, usw.
246        // eigentlich brauchen wir auch nur eine Toolbar...
247}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License