From 027bd6f6f5f0c748ea5f40ed813f3426452c3b5e Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 8 Feb 2015 10:18:38 +0100 Subject: [PATCH] Basic mainwindow is back (not functional yet) --- src/mainwindow.cpp | 99 +++++++++++++++++++++++++++------------------- src/mainwindow.h | 8 ++-- 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d98114f..7789c74 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,58 +1,74 @@ -/*************************************************************************** - * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#include "mainwindow.h" -#include "danbooruclientview.h" -#include "model/danboorupostmodel.h" +/* + * Copyright 2015 Luca Beltrame + * + * This file is part of Danbooru Client. + * + * Danbooru Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Danbooru Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Danbooru Client. If not, see . + */ #include #include -#include -#include +#include +#include +#include +#include +#include -#include +#include +#include +#include +#include + +#include "libdanbooru/danbooruservice.h" +#include "libdanbooru/danboorupost.h" +#include "model/danboorupostmodel.h" +#include "mainwindow.h" namespace Danbooru { -DanbooruMainWindow::DanbooruMainWindow() - : KXmlGuiWindow(), - m_view(new DanbooruClientView(this)), - m_service(0), - m_model(new(DanbooruPostModel(this))) +DanbooruMainWindow::DanbooruMainWindow(QWidget *parent) + : KXmlGuiWindow(parent), + m_view(0), + m_model(0), + m_service(0) { + auto *m_view = new QQuickWidget(this); // tell the KXmlGuiWindow that this is indeed the main widget + auto *m_model = new DanbooruPostModel(this); setCentralWidget(m_view); + qmlRegisterType("DanbooruClient", 1, 0, "DanbooruPost"); + qmlRegisterType("DanbooruClient", 1, 0, "DanbooruService"); + qRegisterMetaType(); + + auto qmlViewPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + qApp->applicationName() + QChar('/') + QLatin1Literal("danbooruimageview.qml")); + + QQmlContext *ctxt = m_view->rootContext(); + ctxt->setContextProperty("danbooruModel", m_model); + ctxt->setContextProperty("danbooruService", m_service); + m_view->setSource(QUrl::fromLocalFile(qmlViewPath)); + // then, setup our actions setupActions(); // add a status bar statusBar()->show(); - // a call to KXmlGuiWindow::setupGUI() populates the GUI - // with actions, using KXMLGUI. - // It also applies the saved mainwindow settings, if any, and ask the - // mainwindow to automatically save settings if changed: window size, - // toolbar position, icon size, etc. - setupGUI(); + setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create|StatusBar, "danbooru-clientui.rc"); } @@ -71,17 +87,17 @@ void DanbooruMainWindow::setupActions() QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")), i18n("Download"), this); - connectAction->setShortcut(KStandardShortcut::open()); - fetchAction->setShortcut(KStandardShortcut::find()); fetchAction->setEnabled(false); actionCollection()->addAction(QLatin1String("connect"), connectAction); actionCollection()->addAction(QLatin1String("fetch"), fetchAction); + actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open); + actionCollection()->setDefaultShortcut(fetchAction, KStandardShortcut::Find); // actionCollection()->removeAction(actionCollection()->action("help_contents")); KStandardAction::quit(qApp, SLOT(close()), actionCollection()); connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard); - connect(fetch, SIGNAL(triggered(bool)), this, SLOT(downloadPosts())); + connect(fetchAction, &QAction::triggered, this, &DanbooruMainWindow::downloadPosts); } @@ -99,6 +115,9 @@ void DanbooruMainWindow::downloadPosts() if (!m_service) { return; } + + m_service->getPostList(1, QStringList(), 10); + } void DanbooruMainWindow::optionsPreferences() @@ -107,5 +126,3 @@ void DanbooruMainWindow::optionsPreferences() } } // namespace Danbooru - -#include "DanbooruMainWindow.moc" diff --git a/src/mainwindow.h b/src/mainwindow.h index 8a81a63..0228b58 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,7 +23,9 @@ #ifndef DANBOORU_CLIENT_H #define DANBOORU_CLIENT_H -#include +#include + +class QQuickWidget; namespace Danbooru { @@ -48,7 +50,7 @@ public: /** * Default Constructor */ - DanbooruMainWindow(); + DanbooruMainWindow(QWidget* parent=0); /** * Default Destructor @@ -65,7 +67,7 @@ private: void setupConnections(); private: - DanbooruClientView *m_view; + QQuickWidget *m_view; DanbooruPostModel *m_model; DanbooruService *m_service; DanbooruConnectWidget *m_connectWidget;