Basic mainwindow is back (not functional yet)
This commit is contained in:
parent
d914dd9744
commit
027bd6f6f5
2 changed files with 63 additions and 44 deletions
|
@ -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 <lbeltrame@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <KStatusBar>
|
||||
|
||||
#include <QAction>
|
||||
#include <KActionCollection>
|
||||
#include <KStandardAction>
|
||||
#include <QQuickWidget>
|
||||
#include <QQmlContext>
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
|
||||
#include <KLocale>
|
||||
#include <kactioncollection.h>
|
||||
#include <KStandardAction>
|
||||
#include <KLocalizedString>
|
||||
#include <kdeclarative.h>
|
||||
|
||||
#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<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost");
|
||||
qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
|
||||
qRegisterMetaType<DanbooruPost::Rating>();
|
||||
|
||||
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"
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
#ifndef DANBOORU_CLIENT_H
|
||||
#define DANBOORU_CLIENT_H
|
||||
|
||||
#include <KXmlGuiWindow>
|
||||
#include <kxmlguiwindow.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue