Mercurial > retraceit
comparison src/mainwindow.cpp @ 0:147b08bc7d64
Initial commit of a basic Application framework.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Mar 2015 12:41:52 +0100 |
parents | |
children | 97d2c8869c39 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:147b08bc7d64 |
---|---|
1 /* Copyright (C) 2014 by Intevation GmbH | |
2 * | |
3 * This file is Free Software under the GNU GPL (v>=2) | |
4 * and comes with ABSOLUTELY NO WARRANTY! | |
5 * See LICENSE.txt for details. | |
6 */ | |
7 | |
8 /** @file See mainwindow.h */ | |
9 #include "mainwindow.h" | |
10 | |
11 #include "constants.h" | |
12 | |
13 #include <QDebug> | |
14 #include <QDialog> | |
15 #include <QWidget> | |
16 #include <QHBoxLayout> | |
17 #include <QLabel> | |
18 #include <QPushButton> | |
19 #include <QDir> | |
20 #include <QFileDialog> | |
21 #include <QMessageBox> | |
22 #include <QApplication> | |
23 #include <QDragEnterEvent> | |
24 #include <QDragLeaveEvent> | |
25 #include <QDropEvent> | |
26 #include <QDragMoveEvent> | |
27 #include <QMimeData> | |
28 #include <QStandardPaths> | |
29 #include <QStyle> | |
30 #include <QStatusBar> | |
31 | |
32 MainWindow::MainWindow() : | |
33 mHasValidFolder(false) | |
34 { | |
35 setStatusBar(new QStatusBar()); | |
36 | |
37 setupGUI(); | |
38 readSettings(); | |
39 setAcceptDrops(true); | |
40 //QIcon windowIcon = QIcon(":/icon-64.png"); | |
41 //setWindowIcon(windowIcon); | |
42 | |
43 } | |
44 | |
45 void MainWindow::setupGUI() | |
46 { | |
47 } | |
48 | |
49 void MainWindow::showErrorMessage(const QString& errMsg) { | |
50 QMessageBox::warning(this, tr("Error!"), errMsg); | |
51 statusBar()->showMessage(errMsg); | |
52 } | |
53 | |
54 void MainWindow::closeEvent(QCloseEvent *event) { | |
55 mSettings.setValue("geometry", saveGeometry()); | |
56 mSettings.setValue("windowState", saveState()); | |
57 QMainWindow::closeEvent(event); | |
58 } | |
59 | |
60 void MainWindow::readSettings() { | |
61 restoreGeometry(mSettings.value("geometry").toByteArray()); | |
62 restoreState(mSettings.value("windowState").toByteArray()); | |
63 } | |
64 | |
65 void MainWindow::dragEnterEvent(QDragEnterEvent *event) | |
66 { | |
67 if (event->mimeData()->hasUrls()) { | |
68 foreach (const QUrl & url, event->mimeData()->urls()) { | |
69 if (url.isLocalFile()) { | |
70 event->acceptProposedAction(); | |
71 return; | |
72 } | |
73 } | |
74 } | |
75 } | |
76 | |
77 void MainWindow::dragMoveEvent(QDragMoveEvent *event) | |
78 { | |
79 if (event->mimeData()->hasUrls()) { | |
80 foreach (const QUrl & url, event->mimeData()->urls()) { | |
81 if (url.isLocalFile()) { | |
82 event->acceptProposedAction(); | |
83 return; | |
84 } | |
85 } | |
86 } | |
87 } | |
88 | |
89 void MainWindow::dropEvent(QDropEvent *event) | |
90 { | |
91 const QMimeData *mimeData = event->mimeData(); | |
92 | |
93 if (mimeData->hasUrls()) { | |
94 foreach (const QUrl & url, mimeData->urls()) { | |
95 if (!url.isLocalFile()) { | |
96 qDebug() << "Ignoring drop of " << url; | |
97 continue; | |
98 } | |
99 } | |
100 } | |
101 } | |
102 | |
103 void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) | |
104 { | |
105 event->accept(); | |
106 } | |
107 | |
108 void MainWindow::setFolder(const QString& folder) | |
109 { | |
110 QFileInfo fi(folder); | |
111 if (!fi.isDir() || !fi.isReadable()) { | |
112 showErrorMessage(tr("Failed to access directory: '%1'").arg(folder)); | |
113 } | |
114 QDir dir = QDir(folder); | |
115 | |
116 // TODO; | |
117 } |