Mercurial > retraceit
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mainwindow.cpp Mon Mar 23 12:41:52 2015 +0100 @@ -0,0 +1,117 @@ +/* Copyright (C) 2014 by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=2) + * and comes with ABSOLUTELY NO WARRANTY! + * See LICENSE.txt for details. + */ + +/** @file See mainwindow.h */ +#include "mainwindow.h" + +#include "constants.h" + +#include <QDebug> +#include <QDialog> +#include <QWidget> +#include <QHBoxLayout> +#include <QLabel> +#include <QPushButton> +#include <QDir> +#include <QFileDialog> +#include <QMessageBox> +#include <QApplication> +#include <QDragEnterEvent> +#include <QDragLeaveEvent> +#include <QDropEvent> +#include <QDragMoveEvent> +#include <QMimeData> +#include <QStandardPaths> +#include <QStyle> +#include <QStatusBar> + +MainWindow::MainWindow() : + mHasValidFolder(false) +{ + setStatusBar(new QStatusBar()); + + setupGUI(); + readSettings(); + setAcceptDrops(true); + //QIcon windowIcon = QIcon(":/icon-64.png"); + //setWindowIcon(windowIcon); + +} + +void MainWindow::setupGUI() +{ +} + +void MainWindow::showErrorMessage(const QString& errMsg) { + QMessageBox::warning(this, tr("Error!"), errMsg); + statusBar()->showMessage(errMsg); +} + +void MainWindow::closeEvent(QCloseEvent *event) { + mSettings.setValue("geometry", saveGeometry()); + mSettings.setValue("windowState", saveState()); + QMainWindow::closeEvent(event); +} + +void MainWindow::readSettings() { + restoreGeometry(mSettings.value("geometry").toByteArray()); + restoreState(mSettings.value("windowState").toByteArray()); +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) { + foreach (const QUrl & url, event->mimeData()->urls()) { + if (url.isLocalFile()) { + event->acceptProposedAction(); + return; + } + } + } +} + +void MainWindow::dragMoveEvent(QDragMoveEvent *event) +{ + if (event->mimeData()->hasUrls()) { + foreach (const QUrl & url, event->mimeData()->urls()) { + if (url.isLocalFile()) { + event->acceptProposedAction(); + return; + } + } + } +} + +void MainWindow::dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + + if (mimeData->hasUrls()) { + foreach (const QUrl & url, mimeData->urls()) { + if (!url.isLocalFile()) { + qDebug() << "Ignoring drop of " << url; + continue; + } + } + } +} + +void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); +} + +void MainWindow::setFolder(const QString& folder) +{ + QFileInfo fi(folder); + if (!fi.isDir() || !fi.isReadable()) { + showErrorMessage(tr("Failed to access directory: '%1'").arg(folder)); + } + QDir dir = QDir(folder); + + // TODO; +}