diff --git a/plan/libs/ui/welcome/WelcomeView.cpp b/plan/libs/ui/welcome/WelcomeView.cpp
index 6c14d145aad..4944fc85819 100644
--- a/plan/libs/ui/welcome/WelcomeView.cpp
+++ b/plan/libs/ui/welcome/WelcomeView.cpp
@@ -1,319 +1,319 @@
/* This file is part of the KDE project
Copyright (C) 2017 Dag Andersen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "WelcomeView.h"
#include "kptcommand.h"
#include "kptdebug.h"
#include "WhatsThis.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
const QLoggingCategory &PLANWELCOME_LOG()
{
static const QLoggingCategory category("calligra.plan.welcome");
return category;
}
#define debugWelcome qCDebug(PLANWELCOME_LOG)
#define warnWelcome qCWarning(PLANWELCOME_LOG)
#define errorWelcome qCCritical(PLANWELCOME_LOG)
namespace KPlato
{
class RecentFilesModel : public QStringListModel
{
public:
RecentFilesModel(QObject *parent = 0);
Qt::ItemFlags flags(const QModelIndex &idx) const;
QVariant data(const QModelIndex &idx, int role) const;
};
RecentFilesModel::RecentFilesModel(QObject *parent)
: QStringListModel(parent)
{
}
Qt::ItemFlags RecentFilesModel::flags(const QModelIndex &idx) const
{
Qt::ItemFlags f = (QStringListModel::flags(idx) & ~Qt::ItemIsEditable);
return f;
}
QVariant RecentFilesModel::data(const QModelIndex &idx, int role) const
{
switch(role) {
case Qt::DecorationRole:
return QIcon::fromTheme(QStringLiteral("document-open"));
break;
case Qt::FontRole: break;
default:
break;
}
return QStringListModel::data(idx, role);
}
//-----------------------------------
WelcomeView::WelcomeView(KoPart *part, KoDocument *doc, QWidget *parent)
: ViewBase(part, doc, parent)
, m_projectdialog(0)
, m_filedialog(0)
{
widget.setupUi(this);
widget.recentProjects->setBackgroundRole(QPalette::Midlight);
WhatsThis::add(widget.newProjectBtn,
i18nc("whatsthis",
""
"Create a new project
"
"Creates a new project with default values defined in"
" Settings."
"
Opens the project dialog"
" so you can define project specific properties like"
" Project Name,"
" Target Start"
" and - End times."
"
More..."
"
"));
WhatsThis::add(widget.createResourceFileBtn,
i18nc("whatsthis",
""
"Shared resources
"
"Create a shared resources file."
"
This enables you to only create your resources once,"
" you just refer to your resources file when you create a new project."
"
Resources can also be shared between projects"
" to avoid overbooking resources across projects."
"
Shared resources must be defined in a separate file."
"
More..."
"
"));
WhatsThis::add(widget.recentProjects,
i18nc("whatsthis",
""
"Recent Projects
"
"
A list of the 10 most recent project files opened.
"
"
This enables you to quickly open projects you have worked on recently."
"
More..."
"
"));
WhatsThis::add(widget.contextHelp,
i18nc("whatsthis",
""
"Context help
"
- "Help is available many places using What's This."
+ "Help is available many places using What's This.
"
"It is activated using the menu entry Help->What's this?"
- " or the keybord shortcut Shift+F1.
"
- "In dialogs it is available via the ? in the dialog title bar."
+ " or the keyboard shortcut Shift+F1.
"
+ "In dialogs it is available via the ? in the dialog title bar.
"
"If you see More... in the text,"
- " pressing it will display more information from online resources in you browser."
+ " pressing it will display more information from online resources in your browser."
"
"));
WhatsThis::add(widget.otherResourcesLabel,
i18nc("whatsthis",
""
"Other resources
"
"Here you find links to online resources."
" Information will be opened in you browser."
"
"));
m_model = new RecentFilesModel(this);
widget.recentProjects->setModel(m_model);
setupGui();
connect(widget.newProjectBtn, SIGNAL(clicked(bool)), this, SLOT(slotNewProject()));
connect(widget.createResourceFileBtn, SIGNAL(clicked(bool)), this, SLOT(slotCreateResourceFile()));
connect(widget.openProjectBtn, SIGNAL(clicked(bool)), this, SLOT(slotOpenProject()));
connect(widget.introductionBtn, SIGNAL(clicked(bool)), this, SIGNAL(showIntroduction()));
connect(widget.recentProjects->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(slotRecentFileSelected(const QItemSelection&)));
}
WelcomeView::~WelcomeView()
{
debugWelcome;
}
void WelcomeView::setRecentFiles(const QStringList &files)
{
QStringList lst;
for (const QString &s : files) {
lst.prepend(s);
}
m_model->setStringList(lst);
widget.recentProjects->resizeColumnToContents(0);
}
void WelcomeView::updateReadWrite(bool /*readwrite */)
{
}
void WelcomeView::setGuiActive(bool activate)
{
debugPlan<show();
m_projectdialog->raise();
m_projectdialog->activateWindow();
}
}
void WelcomeView::slotProjectEditFinished(int result)
{
qDebug()<(sender());
if (dia == 0) {
return;
}
if (result == QDialog::Accepted) {
MacroCommand *cmd = dia->buildCommand();
if (cmd) {
cmd->execute();
delete cmd;
koDocument()->setModified(true);
}
emit projectCreated();
emit selectDefaultView();
emit finished();
}
dia->deleteLater();
}
void WelcomeView::slotCreateResourceFile()
{
QString file = QStandardPaths::locate(QStandardPaths::AppDataLocation, "templates/.source/SharedResources.plant");
emit openTemplate(QUrl::fromUserInput(file));
emit finished();
}
void WelcomeView::slotOpenProject()
{
if (m_projectdialog) {
qWarning()<setFileMode(QFileDialog::ExistingFile);
m_filedialog->setNameFilters(QStringList()<<"Plan files (*.plan)");
m_filedialog->setOption(QFileDialog::HideNameFilterDetails, true);
connect(m_filedialog, SIGNAL(finished(int)), this, SLOT(slotOpenFileFinished(int)));
}
m_filedialog->show();
m_filedialog->raise();
m_filedialog->activateWindow();
}
}
void WelcomeView::slotOpenFileFinished(int result)
{
QFileDialog *dia = qobject_cast(sender());
if (dia == 0) {
return;
}
if (result == QDialog::Accepted) {
QUrl url = dia->selectedUrls().value(0);
if (!url.isEmpty() && mainWindow()->openDocument(url)) {
emit finished();
}
}
dia->deleteLater();
}
void WelcomeView::slotLoadSharedResources(const QString &file, const QUrl &projects, bool loadProjectsAtStartup)
{
QUrl url(file);
if (url.scheme().isEmpty()) {
url.setScheme("file");
}
if (url.isValid()) {
emit loadSharedResources(url, loadProjectsAtStartup ? projects :QUrl());
}
}
} // namespace KPlato