1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/***************************************************************************
* *
* This file is part of the Fotowall project, *
* http://www.enricoros.com/opensource/fotowall *
* *
* Copyright (C) 2009 by Enrico Ros <enrico.ros@gmail.com> *
* *
* 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. *
* *
***************************************************************************/
#include "HomeAppliance.h"
#include "Shared/PixmapButton.h"
#include "App.h"
#include "HomeScene.h"
#include "Settings.h"
#include "UrlHistoryBox.h"
#include "Workflow.h"
#include <QHBoxLayout>
/** File (Open) groupbox **/
class FileBoxWidget : public GroupBoxWidget
{
public:
PixmapButton * openButton;
FileBoxWidget()
: openButton(0)
{
// our layout
QHBoxLayout * lay = new QHBoxLayout(this);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(0);
// add open button
openButton = new PixmapButton(this);
openButton->setFixedSize(QSize(64, 60));
openButton->setToolTip(tr("Open"));
openButton->setPixmap(QPixmap(":/data/action-open.png"));
lay->addWidget(openButton);
}
};
/** Home Appliance **/
HomeAppliance::HomeAppliance(QObject *parent)
: QObject(parent)
, m_scene(0)
, m_fileBox(0)
, m_historyBox(0)
{
// create and set the scene
m_scene = new HomeScene;
connect(m_scene, SIGNAL(keyPressed(int)), this, SLOT(slotSceneKeyPressed(int)));
connect(m_scene, SIGNAL(startCanvas()), this, SLOT(slotStartCanvas()));
#ifndef NO_WORDCLOUD_APPLIANCE
connect(m_scene, SIGNAL(startWordcloud()), this, SLOT(slotStartWordcloud()));
#endif
connect(m_scene, SIGNAL(startWizard()), this, SLOT(slotStartWizard()));
sceneSet(m_scene);
// create the History Box, if enough history
QList<QUrl> recentUrls = App::settings->recentFotowallUrls();
QPalette brightPal;
brightPal.setBrush(QPalette::Window, QColor(255, 255, 255, 128));
if (!recentUrls.isEmpty()) {
m_historyBox = new UrlHistoryBox(recentUrls);
m_historyBox->setTitle(tr("RECENT FILES"));
m_historyBox->setBorderFlags(0x0000);
m_historyBox->setCheckable(false);
m_historyBox->setPalette(brightPal);
m_historyBox->setAutoFillBackground(true);
connect(m_historyBox, SIGNAL(urlClicked(const QUrl &)), this, SLOT(slotLoadCanvas(const QUrl &)));
connect(m_historyBox, SIGNAL(urlRemoved(const QUrl &)), this, SLOT(slotRemoveFromHistory(const QUrl &)));
topbarAddWidget(m_historyBox);
}
// create the File Box
m_fileBox = new FileBoxWidget;
m_fileBox->setTitle(tr("OPEN"));
m_fileBox->setBorderFlags(0x0000);
m_fileBox->setCheckable(false);
m_fileBox->setPalette(brightPal);
m_fileBox->setAutoFillBackground(true);
connect(m_fileBox->openButton, SIGNAL(clicked()), this, SLOT(slotOpenFile()));
topbarAddWidget(m_fileBox);
}
HomeAppliance::~HomeAppliance()
{
delete m_fileBox;
delete m_historyBox;
delete m_scene;
}
void HomeAppliance::slotSceneKeyPressed(int qtKey)
{
// pressed a number, activate relative Url
if (qtKey >= Qt::Key_1 && qtKey <= Qt::Key_9) {
QUrl url = m_historyBox->urlForEntry(qtKey - Qt::Key_0 - 1);
if (!url.isEmpty())
slotLoadCanvas(url);
}
}
void HomeAppliance::slotLoadCanvas(const QUrl & url)
{
// handle fotowall files
if (App::isFotowallFile(url.toString())) {
App::workflow->loadCanvas_A(url.toString());
return;
}
// handle other files
qWarning("HomeAppliance::slotLoadCanvas: don't know how to load URL '%s'", qPrintable(url.toString()));
}
void HomeAppliance::slotRemoveFromHistory(const QUrl & url)
{
// remove url
App::settings->removeRecentFotowallUrl(url);
// change urls
QList<QUrl> recentUrls = App::settings->recentFotowallUrls();
m_historyBox->changeUrls(recentUrls, false);
}
void HomeAppliance::slotOpenFile()
{
App::workflow->loadCanvas_A();
}
void HomeAppliance::slotStartCanvas()
{
App::workflow->startCanvas_A();
}
#ifndef NO_WORDCLOUD_APPLIANCE
void HomeAppliance::slotStartWordcloud()
{
App::workflow->startWordcloud_A();
}
#endif
void HomeAppliance::slotStartWizard()
{
HERE
}
|