Initial implementation of main window + view widget

This commit is contained in:
Luca Beltrame 2013-07-28 18:14:55 +02:00
parent c1bde86980
commit 1d09d12345
5 changed files with 217 additions and 184 deletions

View file

@ -1,8 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="danbooru_client" version="1">
<MenuBar>
<Menu name="move"><text>&amp;Move</text>
<Action name="switch_action" />
</Menu>
</MenuBar>
<kpartgui name="danbooru_client" version="3">
<ToolBar name="mainToolBar" >
<text>Main Toolbar</text>
<Action name="connect" />
<Action name="fetch" />
<Action name="batchDownload" />
<Action name="poolDownload" />
<Action name="tagDisplay" />
<ActionList name="dynamicActionlist" />
</ToolBar>
<MenuBar>
<Menu name="file" >
<text>&amp;File</text>
<Action name="connect" />
<Action name="fetch" />
<Action name="batchDownload" />
<Action name="clean" />
</Menu>
</MenuBar>
</kpartgui>

View file

@ -17,44 +17,73 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "danbooru_clientview.h"
#include "settings.h"
#include "danbooruclientview.h"
#include <KLocale>
#include <QtGui/QLabel>
// Own
danbooru_clientView::danbooru_clientView(QWidget *)
{
ui_danbooru_clientview_base.setupUi(this);
settingsChanged();
setAutoFillBackground(true);
}
#include "model/danboorupostmodel.h"
#include "model/danboorupostdelegate.h"
danbooru_clientView::~danbooru_clientView()
{
// Qt
}
#include <QTimer>
void danbooru_clientView::switchColors()
{
// switch the foreground/background colors of the label
QColor color = Settings::col_background();
Settings::setCol_background( Settings::col_foreground() );
Settings::setCol_foreground( color );
// KDE
settingsChanged();
}
#include <KRun>
#include <KFileDialog>
void danbooru_clientView::settingsChanged()
{
QPalette pal;
pal.setColor( QPalette::Window, Settings::col_background());
pal.setColor( QPalette::WindowText, Settings::col_foreground());
ui_danbooru_clientview_base.kcfg_sillyLabel->setPalette( pal );
namespace Danbooru {
// i18n : internationalization
ui_danbooru_clientview_base.kcfg_sillyLabel->setText( i18n("This project is %1 days old",Settings::val_time()) );
emit signalChangeStatusbar( i18n("Settings changed") );
}
DanbooruClientView::DanbooruClientView(QWidget * parent): QWidget(parent),
m_model(new DanbooruPostModel(this)),
m_delegate(0),
m_service(0),
m_timer(0)
{
setupUi(this);
#include "danbooru_clientview.moc"
m_delegate = new DanbooruPostDelegate(m_listView);
m_listView->setFlow(QListView::LeftToRight);
m_listView->setResizeMode(QListView::Adjust);
m_listView->setWrapping(true);
m_listView->setViewMode(QListView::IconMode);
m_listView->setGridSize(QSize(256,256));
m_listView->setModel(m_model);
m_listView->setItemDelegate(m_delegate);
// signal-slot connections
connect(m_delegate, SIGNAL(postDownloadRequested(KUrl)), this,
SLOT(slotHandleDownload(KUrl)));
connect(m_delegate, SIGNAL(postViewRequested(KUrl)), this,
SLOT(slotHandleView(KUrl)));
// connect(m_listView, SIGNAL(clicked(const QModelIndex&)), parent(),
// SLOT(displayInfo(const QModelIndex&));
}
DanbooruClientView::~DanbooruClientView()
{
}
void DanbooruClientView::slotHandleDownload(KUrl url)
{
// TODO
Q_UNUSED(url)
}
void DanbooruClientView::slotHandleView(KUrl url)
{
KRun* runViewer = new KRun(url, this /*window*/, 0 /*mode*/,
false /*isLocalFile*/,
true /*showProgressInfo*/, "" /*asn*/);
runViewer->setAutoDelete(true);
}
} // namespace Danbooru

View file

@ -20,54 +20,58 @@
#ifndef DANBOORU_CLIENTVIEW_H
#define DANBOORU_CLIENTVIEW_H
#include <QtGui/QWidget>
#include "ui_danbooruclientview.h"
#include "ui_danbooru_clientview_base.h"
#include "kurl.h"
class QPainter;
class KUrl;
#include <QWidget>
/**
* This is the main view class for danbooru_client. Most of the non-menu,
* non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
* here.
*
* @short Main view
* @author %{AUTHOR} <%{EMAIL}>
* @version %{VERSION}
*/
class QTimer;
class danbooru_clientView : public QWidget, public Ui::danbooru_clientview_base
{
Q_OBJECT
public:
/**
* Default constructor
*/
danbooru_clientView(QWidget *parent);
namespace Danbooru {
class DanbooruPostModel;
class DanbooruPostDelegate;
class DanbooruService;
/**
* Destructor
* This is the main view class for danbooru_client. Most of the non-menu,
* non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
* here.
*
* @short Main view
* @author %{AUTHOR} <%{EMAIL}>
* @version %{VERSION}
*/
virtual ~danbooru_clientView();
private:
Ui::danbooru_clientview_base ui_danbooru_clientview_base;
class DanbooruClientView : public QWidget, public Ui::DanbooruClientView
{
Q_OBJECT
signals:
/**
* Use this signal to change the content of the statusbar
*/
void signalChangeStatusbar(const QString& text);
public:
/**
* Default constructor
*/
DanbooruClientView(QWidget *parent=0);
/**
* Use this signal to change the content of the caption
*/
void signalChangeCaption(const QString& text);
/**
* Destructor
*/
virtual ~DanbooruClientView();
private Q_SLOTS:
void slotHandleDownload(KUrl);
void slotHandleView(KUrl);
private:
DanbooruPostModel* m_model;
DanbooruPostDelegate* m_delegate;
DanbooruService* m_service;
QTimer* m_timer;
private slots:
void switchColors();
void settingsChanged();
};
} // namespace Danbooru
#endif // danbooru_clientVIEW_H

View file

@ -17,13 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "danbooru_client.h"
#include "danbooru_clientview.h"
#include "settings.h"
#include <QtGui/QDropEvent>
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
#include "mainwindow.h"
#include "danbooruclientview.h"
#include "model/danboorupostmodel.h"
#include <KConfigDialog>
#include <KStatusBar>
@ -34,75 +30,65 @@
#include <KLocale>
danbooru_client::danbooru_client()
: KXmlGuiWindow(),
m_view(new danbooru_clientView(this)),
m_printer(0)
{
// accept dnd
setAcceptDrops(true);
namespace Danbooru {
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(m_view);
DanbooruMainWindow::DanbooruMainWindow()
: KXmlGuiWindow(),
m_view(new DanbooruClientView(this)),
m_service(0),
m_model(new(DanbooruPostModel(this)))
{
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(m_view);
// then, setup our actions
setupActions();
// then, setup our actions
setupActions();
// add a status bar
statusBar()->show();
// 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();
}
// 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();
danbooru_client::~danbooru_client()
{
}
void danbooru_client::setupActions()
{
KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
// custom menu and menu item - the slot is in the class danbooru_clientView
KAction *custom = new KAction(KIcon("colorize"), i18n("Swi&tch Colors"), this);
actionCollection()->addAction( QLatin1String("switch_action"), custom );
connect(custom, SIGNAL(triggered(bool)), m_view, SLOT(switchColors()));
}
void danbooru_client::fileNew()
{
// this slot is called whenever the File->New menu is selected,
// the New shortcut is pressed (usually CTRL+N) or the New toolbar
// button is clicked
// create a new window
(new danbooru_client)->show();
}
void danbooru_client::optionsPreferences()
{
// The preference dialog is derived from prefs_base.ui
//
// compare the names of the widgets in the .ui file
// to the names of the variables in the .kcfg file
//avoid to have 2 dialogs shown
if ( KConfigDialog::showDialog( "settings" ) ) {
return;
}
KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
QWidget *generalSettingsDlg = new QWidget;
ui_prefs_base.setupUi(generalSettingsDlg);
dialog->addPage(generalSettingsDlg, i18n("General"), "package_setting");
connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->show();
}
#include "danbooru_client.moc"
DanbooruMainWindow::~DanbooruMainWindow()
{
}
void DanbooruMainWindow::setupActions()
{
// KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
// KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
//
// KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
//
// // custom menu and menu item - the slot is in the class DanbooruMainWindowView
// KAction *custom = new KAction(KIcon("colorize"), i18n("Swi&tch Colors"), this);
// actionCollection()->addAction( QLatin1String("switch_action"), custom );
// connect(custom, SIGNAL(triggered(bool)), m_view, SLOT(switchColors()));
}
void DanbooruMainWindow::connectToBoard()
{
}
void DanbooruMainWindow::downloadPosts()
{
}
void DanbooruMainWindow::optionsPreferences()
{
}
} // namespace Danbooru
#include "DanbooruMainWindow.moc"

View file

@ -23,49 +23,49 @@
#include <KXmlGuiWindow>
#include "ui_prefs_base.h"
namespace Danbooru {
class danbooru_clientView;
class QPrinter;
class KToggleAction;
class KUrl;
/**
* This class serves as the main window for danbooru_client. It handles the
* menus, toolbars and status bars.
*
* @short Main window class
* @author %{AUTHOR} <%{EMAIL}>
* @version %{VERSION}
*/
class danbooru_client : public KXmlGuiWindow
{
Q_OBJECT
public:
/**
* Default Constructor
*/
danbooru_client();
class DanbooruClientView;
class DanbooruService;
class DanbooruPostModel;
/**
* Default Destructor
* This class serves as the main window for danbooru_client. It handles the
* menus, toolbars and status bars.
*
* @short Main window class
* @author Luca Beltrame <lbeltrame@kde.org>
* @version 0.01
*/
virtual ~danbooru_client();
class DanbooruMainWindow : public KXmlGuiWindow
{
Q_OBJECT
public:
/**
* Default Constructor
*/
DanbooruMainWindow();
private slots:
void fileNew();
void optionsPreferences();
/**
* Default Destructor
*/
virtual ~DanbooruMainWindow();
private:
void setupActions();
private Q_SLOTS:
void connectToBoard();
void downloadPosts();
void optionsPreferences();
private:
Ui::prefs_base ui_prefs_base ;
danbooru_clientView *m_view;
private:
void setupActions();
QPrinter *m_printer;
KToggleAction *m_toolbarAction;
KToggleAction *m_statusbarAction;
};
private:
DanbooruClientView *m_view;
DanbooruPostModel* m_model;
DanbooruService* m_service;
};
} // namespace Danbooru
#endif // _DANBOORU_CLIENT_H_