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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QDropEvent>
#include <QMimeData>
MainWindow::MainWindow(Library &library, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
library(library),
pageFactory(library, this)
{
ui->setupUi(this);
page = NULL;
this->setAcceptDrops(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setPage(const QString& pageName, const QString& initString)
{
std::cout << "setpage " << pageName.toStdString() << std::endl;
if (page) {
page->deleteLater();
// delete page; // also removes from parent
}
page = pageFactory.pageForKey(pageName);
if (page) {
this->ui->verticalLayout->addWidget(page);
this->pageId = pageName;
page->initFromQuery(initString);
} else {
this->page = NULL;
}
}
void MainWindow::setPage(const QString &pageName)
{
setPage(pageName, QString());
}
QString MainWindow::activePageId() {
return pageId;
}
Page *MainWindow::getPage() {
return page;
}
MainBackgroundWidget *MainWindow::getCentralWidget() {
return ui->centralWidget;
}
void MainWindow::dragMoveEvent(QDragMoveEvent *event) {
event->accept();
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
event->accept();
}
void MainWindow::dropEvent(QDropEvent *event) {
if (!event->mimeData()) {
event->dropAction();
return;
}
const QList<QUrl> urls = event->mimeData()->urls();
bool addedDirectory = false;
for (int i=0; i < urls.length(); ++i) {
const QUrl& url = urls.at(i);
if (QDir(url.path()).exists()) {
library.addSearchDirectory(SearchDirectory(url.path()));
addedDirectory = true;
}
}
if (addedDirectory) {
event->accept();
library.startSearch();
qDebug() << "search dirs added!";
} else {
event->accept();
}
}