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}>                            *
 | 
					 * Copyright 2015 Luca Beltrame <lbeltrame@kde.org>
 | 
				
			||||||
 *                                                                         *
 | 
					 *
 | 
				
			||||||
 *   This program is free software; you can redistribute it and/or modify  *
 | 
					 * This file is part of Danbooru Client.
 | 
				
			||||||
 *   it under the terms of the GNU General Public License as published by  *
 | 
					 *
 | 
				
			||||||
 *   the Free Software Foundation; either version 2 of the License, or     *
 | 
					 * Danbooru Client is free software: you can redistribute it and/or modify
 | 
				
			||||||
 *   (at your option) any later version.                                   *
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 *                                                                         *
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 *   This program is distributed in the hope that it will be useful,       *
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 | 
					 *
 | 
				
			||||||
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 | 
					 * Danbooru Client is distributed in the hope that it will be useful,
 | 
				
			||||||
 *   GNU General Public License for more details.                          *
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 *                                                                         *
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 *   You should have received a copy of the GNU General Public License     *
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 *   along with this program; if not, write to the                         *
 | 
					 *
 | 
				
			||||||
 *   Free Software Foundation, Inc.,                                       *
 | 
					 * You should have received a copy of the GNU General Public License
 | 
				
			||||||
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 | 
					 * along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 ***************************************************************************/
 | 
					 */
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "mainwindow.h"
 | 
					 | 
				
			||||||
#include "danbooruclientview.h"
 | 
					 | 
				
			||||||
#include "model/danboorupostmodel.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <KStatusBar>
 | 
					#include <KStatusBar>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QAction>
 | 
					#include <QAction>
 | 
				
			||||||
#include <KActionCollection>
 | 
					#include <QQuickWidget>
 | 
				
			||||||
#include <KStandardAction>
 | 
					#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
 | 
					namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DanbooruMainWindow::DanbooruMainWindow()
 | 
					DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
    : KXmlGuiWindow(),
 | 
					    : KXmlGuiWindow(parent),
 | 
				
			||||||
      m_view(new DanbooruClientView(this)),
 | 
					      m_view(0),
 | 
				
			||||||
      m_service(0),
 | 
					      m_model(0),
 | 
				
			||||||
      m_model(new(DanbooruPostModel(this)))
 | 
					      m_service(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    auto *m_view = new QQuickWidget(this);
 | 
				
			||||||
    // tell the KXmlGuiWindow that this is indeed the main widget
 | 
					    // tell the KXmlGuiWindow that this is indeed the main widget
 | 
				
			||||||
 | 
					    auto *m_model = new DanbooruPostModel(this);
 | 
				
			||||||
    setCentralWidget(m_view);
 | 
					    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
 | 
					    // then, setup our actions
 | 
				
			||||||
    setupActions();
 | 
					    setupActions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // add a status bar
 | 
					    // add a status bar
 | 
				
			||||||
    statusBar()->show();
 | 
					    statusBar()->show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // a call to KXmlGuiWindow::setupGUI() populates the GUI
 | 
					    setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create|StatusBar, "danbooru-clientui.rc");
 | 
				
			||||||
    // 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();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,17 +87,17 @@ void DanbooruMainWindow::setupActions()
 | 
				
			||||||
    QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
 | 
					    QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
 | 
				
			||||||
                                       i18n("Download"), this);
 | 
					                                       i18n("Download"), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connectAction->setShortcut(KStandardShortcut::open());
 | 
					 | 
				
			||||||
    fetchAction->setShortcut(KStandardShortcut::find());
 | 
					 | 
				
			||||||
    fetchAction->setEnabled(false);
 | 
					    fetchAction->setEnabled(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    actionCollection()->addAction(QLatin1String("connect"), connectAction);
 | 
					    actionCollection()->addAction(QLatin1String("connect"), connectAction);
 | 
				
			||||||
    actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
 | 
					    actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
 | 
				
			||||||
 | 
					    actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open);
 | 
				
			||||||
 | 
					    actionCollection()->setDefaultShortcut(fetchAction, KStandardShortcut::Find);
 | 
				
			||||||
    // actionCollection()->removeAction(actionCollection()->action("help_contents"));
 | 
					    // actionCollection()->removeAction(actionCollection()->action("help_contents"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    KStandardAction::quit(qApp, SLOT(close()), actionCollection());
 | 
					    KStandardAction::quit(qApp, SLOT(close()), actionCollection());
 | 
				
			||||||
    connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard);
 | 
					    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) {
 | 
					    if (!m_service) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_service->getPostList(1, QStringList(), 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruMainWindow::optionsPreferences()
 | 
					void DanbooruMainWindow::optionsPreferences()
 | 
				
			||||||
| 
						 | 
					@ -107,5 +126,3 @@ void DanbooruMainWindow::optionsPreferences()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "DanbooruMainWindow.moc"
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,9 @@
 | 
				
			||||||
#ifndef DANBOORU_CLIENT_H
 | 
					#ifndef DANBOORU_CLIENT_H
 | 
				
			||||||
#define DANBOORU_CLIENT_H
 | 
					#define DANBOORU_CLIENT_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <KXmlGuiWindow>
 | 
					#include <kxmlguiwindow.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class QQuickWidget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Danbooru
 | 
					namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -48,7 +50,7 @@ public:
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Default Constructor
 | 
					     * Default Constructor
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    DanbooruMainWindow();
 | 
					    DanbooruMainWindow(QWidget* parent=0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Default Destructor
 | 
					     * Default Destructor
 | 
				
			||||||
| 
						 | 
					@ -65,7 +67,7 @@ private:
 | 
				
			||||||
    void setupConnections();
 | 
					    void setupConnections();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    DanbooruClientView *m_view;
 | 
					    QQuickWidget *m_view;
 | 
				
			||||||
    DanbooruPostModel *m_model;
 | 
					    DanbooruPostModel *m_model;
 | 
				
			||||||
    DanbooruService *m_service;
 | 
					    DanbooruService *m_service;
 | 
				
			||||||
    DanbooruConnectWidget *m_connectWidget;
 | 
					    DanbooruConnectWidget *m_connectWidget;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue