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"> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="danbooru_client" version="1"> <kpartgui name="danbooru_client" version="3">
<MenuBar> <ToolBar name="mainToolBar" >
<Menu name="move"><text>&amp;Move</text> <text>Main Toolbar</text>
<Action name="switch_action" /> <Action name="connect" />
</Menu> <Action name="fetch" />
</MenuBar> <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> </kpartgui>

View file

@ -17,44 +17,73 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/ ***************************************************************************/
#include "danbooru_clientview.h" #include "danbooruclientview.h"
#include "settings.h"
#include <KLocale> // Own
#include <QtGui/QLabel>
danbooru_clientView::danbooru_clientView(QWidget *) #include "model/danboorupostmodel.h"
{ #include "model/danboorupostdelegate.h"
ui_danbooru_clientview_base.setupUi(this);
settingsChanged();
setAutoFillBackground(true);
}
danbooru_clientView::~danbooru_clientView() // Qt
{
} #include <QTimer>
void danbooru_clientView::switchColors() // KDE
{
// switch the foreground/background colors of the label
QColor color = Settings::col_background();
Settings::setCol_background( Settings::col_foreground() );
Settings::setCol_foreground( color );
settingsChanged(); #include <KRun>
} #include <KFileDialog>
void danbooru_clientView::settingsChanged() namespace Danbooru {
{
QPalette pal;
pal.setColor( QPalette::Window, Settings::col_background());
pal.setColor( QPalette::WindowText, Settings::col_foreground());
ui_danbooru_clientview_base.kcfg_sillyLabel->setPalette( pal );
// i18n : internationalization DanbooruClientView::DanbooruClientView(QWidget * parent): QWidget(parent),
ui_danbooru_clientview_base.kcfg_sillyLabel->setText( i18n("This project is %1 days old",Settings::val_time()) ); m_model(new DanbooruPostModel(this)),
emit signalChangeStatusbar( i18n("Settings changed") ); 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 #ifndef DANBOORU_CLIENTVIEW_H
#define 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; #include <QWidget>
class KUrl;
/** class QTimer;
* 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 danbooru_clientView : public QWidget, public Ui::danbooru_clientview_base namespace Danbooru {
{
Q_OBJECT class DanbooruPostModel;
public: class DanbooruPostDelegate;
/** class DanbooruService;
* Default constructor
*/
danbooru_clientView(QWidget *parent);
/** /**
* 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: class DanbooruClientView : public QWidget, public Ui::DanbooruClientView
Ui::danbooru_clientview_base ui_danbooru_clientview_base; {
Q_OBJECT
signals: public:
/** /**
* Use this signal to change the content of the statusbar * Default constructor
*/ */
void signalChangeStatusbar(const QString& text); DanbooruClientView(QWidget *parent=0);
/** /**
* Use this signal to change the content of the caption * Destructor
*/ */
void signalChangeCaption(const QString& text); 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 #endif // danbooru_clientVIEW_H

View file

@ -17,13 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/ ***************************************************************************/
#include "danbooru_client.h" #include "mainwindow.h"
#include "danbooru_clientview.h" #include "danbooruclientview.h"
#include "settings.h" #include "model/danboorupostmodel.h"
#include <QtGui/QDropEvent>
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
#include <KConfigDialog> #include <KConfigDialog>
#include <KStatusBar> #include <KStatusBar>
@ -34,75 +30,65 @@
#include <KLocale> #include <KLocale>
danbooru_client::danbooru_client() namespace Danbooru {
: KXmlGuiWindow(),
m_view(new danbooru_clientView(this)),
m_printer(0)
{
// accept dnd
setAcceptDrops(true);
// tell the KXmlGuiWindow that this is indeed the main widget DanbooruMainWindow::DanbooruMainWindow()
setCentralWidget(m_view); : 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 // 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 // a call to KXmlGuiWindow::setupGUI() populates the GUI
// with actions, using KXMLGUI. // with actions, using KXMLGUI.
// It also applies the saved mainwindow settings, if any, and ask the // It also applies the saved mainwindow settings, if any, and ask the
// mainwindow to automatically save settings if changed: window size, // mainwindow to automatically save settings if changed: window size,
// toolbar position, icon size, etc. // toolbar position, icon size, etc.
setupGUI(); 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 <KXmlGuiWindow>
#include "ui_prefs_base.h" namespace Danbooru {
class danbooru_clientView; class DanbooruClientView;
class QPrinter; class DanbooruService;
class KToggleAction; class DanbooruPostModel;
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();
/** /**
* 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(); * Default Destructor
void optionsPreferences(); */
virtual ~DanbooruMainWindow();
private: private Q_SLOTS:
void setupActions(); void connectToBoard();
void downloadPosts();
void optionsPreferences();
private: private:
Ui::prefs_base ui_prefs_base ; void setupActions();
danbooru_clientView *m_view;
QPrinter *m_printer; private:
KToggleAction *m_toolbarAction; DanbooruClientView *m_view;
KToggleAction *m_statusbarAction; DanbooruPostModel* m_model;
}; DanbooruService* m_service;
};
} // namespace Danbooru
#endif // _DANBOORU_CLIENT_H_ #endif // _DANBOORU_CLIENT_H_