Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWelcomePageWidget.cpp
Go to the documentation of this file.
1
2/* This file is part of the KDE project
3 * SPDX-FileCopyrightText: 2018 Scott Petrovic <scottpetrovic@gmail.com>
4 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
11#include <QDesktopServices>
12#include <QMimeData>
13#include <QPixmap>
14#include <QMessageBox>
15#include <QTemporaryFile>
16#include <QBuffer>
17#include <QNetworkAccessManager>
18#include <QEventLoop>
19#include <QDomDocument>
20
22#include "kactioncollection.h"
23#include "kis_action.h"
24#include "kis_action_manager.h"
26#include <KisMimeDatabase.h>
27#include <KisApplication.h>
28
29#include "KConfigGroup"
30#include "KSharedConfig"
31
32#include <QListWidget>
33#include <QListWidgetItem>
34#include <QMenu>
35#include <QScrollBar>
36
37#include "kis_clipboard.h"
38#include "kis_icon_utils.h"
39#include <kis_painting_tweaks.h>
40#include "KoStore.h"
41#include "kis_config.h"
42#include "KisDocument.h"
43#include <kis_image.h>
44#include <kis_paint_device.h>
45#include <KisPart.h>
46#include <KisKineticScroller.h>
47#include "KisMainWindow.h"
48
50
51#include <QCoreApplication>
52#include <kis_debug.h>
53#include <QDir>
54
55#include <array>
56
57#include "config-updaters.h"
58
59#ifdef ENABLE_UPDATERS
60#ifdef Q_OS_LINUX
62#endif
63
65#endif
66
67#include <klocalizedstring.h>
68#include <KritaVersionWrapper.h>
69
70#include <KisUsageLogger.h>
71#include <QSysInfo>
72#include <kis_config.h>
73#include <kis_image_config.h>
74#include "opengl/kis_opengl.h"
75
76#ifdef Q_OS_WIN
78#endif
79
80#ifdef Q_OS_MACOS
82#endif
83
84#ifdef Q_OS_ANDROID
85#include "KisAndroidDonations.h"
86#include <QFontMetrics>
87#include <QPaintDevice>
88#include <QPainter>
89#include <QPainterPath>
90#include <QRandomGenerator>
91#endif
92
93
94// class to override item height for Breeze since qss seems to not work
95class RecentItemDelegate : public QStyledItemDelegate
96{
97 int itemHeight = 0;
98public:
99 RecentItemDelegate(QObject *parent = 0)
100 : QStyledItemDelegate(parent)
101 {
102 }
103
105 {
106 this->itemHeight = itemHeight;
107 }
108
109 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const override
110 {
111 return QSize(option.rect.width(), itemHeight);
112 }
113};
114
115
117 : QWidget(parent)
118{
119 setupUi(this);
120
121 // URLs that go to web browser...
122 devBuildIcon->setIcon(KisIconUtils::loadIcon("warning"));
123 devBuildLabel->setVisible(false);
124 updaterFrame->setVisible(false);
125 versionNotificationLabel->setVisible(false);
126 bnVersionUpdate->setVisible(false);
127 bnErrorDetails->setVisible(false);
128
129 // Recent docs...
130 recentDocumentsListView->setDragEnabled(false);
131 recentDocumentsListView->viewport()->setAutoFillBackground(false);
132 recentDocumentsListView->setSpacing(2);
133 recentDocumentsListView->installEventFilter(this);
134 recentDocumentsListView->setViewMode(QListView::IconMode);
135 recentDocumentsListView->setSelectionMode(QAbstractItemView::NoSelection);
136 recentDocumentsListView->setVerticalScrollMode(QListView::ScrollPerPixel);
137 recentDocumentsListView->verticalScrollBar()->setSingleStep(50);
138 {
139 QScroller* scroller = KisKineticScroller::createPreconfiguredScroller(recentDocumentsListView);
140 if (scroller) {
141 connect(scroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(slotScrollerStateChanged(QScroller::State)));
142 }
143 }
144 recentDocumentsListView->setContextMenuPolicy(Qt::CustomContextMenu);
145 connect(recentDocumentsListView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(slotRecentDocContextMenuRequest(QPoint)));
147
148 // News widget...
149 QMenu *newsOptionsMenu = new QMenu(this);
150 newsOptionsMenu->setToolTipsVisible(true);
151 m_enableNewsAction = newsOptionsMenu->addAction(i18n("Automatically check for updates"));
152 m_enableNewsAction->setToolTip(i18n("Show news about Krita: this needs internet to retrieve information from the krita.org website"));
153 m_enableNewsAction->setCheckable(true);
154
155 newsOptionsMenu->addSection(i18n("Language"));
156 QAction *newsInfoAction = newsOptionsMenu->addAction(i18n("English news is always up to date."));
157 newsInfoAction->setEnabled(false);
158
159 setupNewsLangSelection(newsOptionsMenu);
160 btnNewsOptions->setMenu(newsOptionsMenu);
161
162 checkNowButton->setIcon(KisIconUtils::loadIcon(QStringLiteral("view-refresh")));
163
164 labelSupportText->setFont(largerFont());
165
166 connect(btnDismisAll, SIGNAL(clicked()), newsWidget, SLOT(dismissAll()));
167 connect(newsWidget, SIGNAL(newsStateChanged(bool)), this, SLOT(newsStateChanged(bool)));
168 newsStateChanged(false);
169
170 connect(m_enableNewsAction, SIGNAL(triggered(bool)), this, SLOT(slotSetNewsEnabled(bool)));
171 connect(enableNewsBox, SIGNAL(clicked(bool)), this, SLOT(slotSetNewsEnabled(bool)));
172 connect(checkNowButton, SIGNAL(clicked()), this, SLOT(slotCheckNews()));
173
174 supporterBadge->hide();
175 wdgAndroidSupportBanner->hide();
176#ifdef Q_OS_ANDROID
177 initDonations();
178#endif
179
180 // We want to enable updates by default, but allow the user the chance to
181 // disable them before making a network connection when they see the option
182 // the first time.
183 bool newsCheckEnabled, newsFirstStartup;
184 {
185 KisConfig cfg(false);
186 newsCheckEnabled = cfg.newsCheckEnabled();
187 newsFirstStartup = cfg.newsFirstStartup();
188 cfg.setNewsFirstStartup(false);
189 }
190
191 m_enableNewsAction->setChecked(newsCheckEnabled);
192 enableNewsBox->setChecked(newsCheckEnabled);
193
194#ifdef ENABLE_UPDATERS
195#ifndef Q_OS_ANDROID
196 // Setup version updater, but do not check for them, unless the user explicitly
197 // wants to check for updates.
198 // * No updater is created for Linux/Steam, Windows/Steam and Windows/Store distributions,
199 // as those stores have their own updating mechanism.
200 // * STEAMAPPID(Windows)/SteamAppId(Linux) environment variable is set when Krita is run from Steam.
201 // The environment variables are not public API.
202 // * MS Store version runs as a package (though we cannot know if it was
203 // installed from the Store or manually with the .msix package)
204#if defined Q_OS_LINUX
205 if (!qEnvironmentVariableIsSet("SteamAppId")) { // do not create updater for linux/steam
206 if (qEnvironmentVariableIsSet("APPIMAGE")) {
207 m_versionUpdater.reset(new KisAppimageUpdater());
208 }
209 // Fall back to the manual updater if the AppImage one doesn't work.
210 if (m_versionUpdater.isNull() || !m_versionUpdater->hasUpdateCapability()) {
211 m_versionUpdater.reset(new KisManualUpdater());
212 }
213 }
214#elif defined Q_OS_WIN
215 if (!KisWindowsPackageUtils::isRunningInPackage() && !qEnvironmentVariableIsSet("STEAMAPPID")) {
216 m_versionUpdater.reset(new KisManualUpdater());
217 KisUsageLogger::log("Non-store package - creating updater");
218 } else {
219 KisUsageLogger::log("detected appx or steam package - not creating the updater");
220 }
221#else
222 // always create updater for MacOS
223 m_versionUpdater.reset(new KisManualUpdater());
224#endif // Q_OS_*
225 if (!m_versionUpdater.isNull()) {
226 connect(bnVersionUpdate, SIGNAL(clicked()), this, SLOT(slotRunVersionUpdate()));
227 connect(bnErrorDetails, SIGNAL(clicked()), this, SLOT(slotShowUpdaterErrorDetails()));
228 connect(m_versionUpdater.data(), SIGNAL(sigUpdateCheckStateChange(KisUpdaterStatus)),
229 this, SLOT(slotSetUpdateStatus(const KisUpdaterStatus&)));
230 }
231#endif // ifndef Q_OS_ANDROID
232#endif // ENABLE_UPDATERS
233
234 if (newsCheckEnabled && !newsFirstStartup) {
236 } else {
237 newsWidget->hide();
238 }
239
240 // Drop area..
241 setAcceptDrops(true);
242}
243
247
249{
250 if (mainWin) {
251 m_mainWindow = mainWin;
252
253 // set the shortcut links from actions (only if a shortcut exists)
254 KisActionManager *actionManager = mainWin->viewManager()->actionManager();
255 updateShortcutLink(newFileLink, newFileLinkShortcut, actionManager->actionByName(QStringLiteral("file_new")));
256 updateShortcutLink(openFileLink, openFileShortcut, actionManager->actionByName(QStringLiteral("file_open")));
257 connect(recentDocumentsListView, SIGNAL(clicked(QModelIndex)), this, SLOT(recentDocumentClicked(QModelIndex)));
258 // we need the view manager to actually call actions, so don't create the connections
259 // until after the view manager is set
260 connect(newFileLink, SIGNAL(clicked(bool)), this, SLOT(slotNewFileClicked()));
261 connect(openFileLink, SIGNAL(clicked(bool)), this, SLOT(slotOpenFileClicked()));
262 connect(clearRecentFilesLink, SIGNAL(clicked(bool)), mainWin, SLOT(clearRecentFiles()));
263
264 KisAction *pasteAction = mainWin->viewManager()->actionManager()->actionByName("edit_paste");
265 connect(pasteAction, SIGNAL(triggered()), this, SLOT(slotPaste()));
266
268
269 // allows RSS news items to apply analytics tracking.
270 Q_EMIT newsWidget->setAnalyticsTracking("?" + analyticsString);
271
273 connect(recentFilesModel, SIGNAL(sigModelIsUpToDate()), this, SLOT(slotRecentFilesModelIsUpToDate()));
274 recentDocumentsListView->setModel(&recentFilesModel->model());
276 }
277}
278
279
281{
282 if (!show) {
283 QString dropFrameStyle = QStringLiteral("QFrame#dropAreaIndicator { border: 2px solid transparent }");
284 dropFrameBorder->setStyleSheet(dropFrameStyle);
285 } else {
286 QColor textColor = qApp->palette().color(QPalette::Text);
287 QColor backgroundColor = qApp->palette().color(QPalette::Window);
289
290 // QColor.name() turns it into a hex/web format
291 QString dropFrameStyle = QString("QFrame#dropAreaIndicator { border: 2px dotted ").append(blendedColor.name()).append(" }") ;
292 dropFrameBorder->setStyleSheet(dropFrameStyle);
293 }
294}
295
297{
298 textColor = qApp->palette().color(QPalette::Text);
299 backgroundColor = qApp->palette().color(QPalette::Window);
300
301 // make the welcome screen labels a subtle color so it doesn't clash with the main UI elements
303 // only apply color to the widget itself, not to the tooltip or something
304 blendedStyle = "QWidget{color: " + blendedColor.name() + "}";
305
306 // what labels to change the color...
307 startTitleLabel->setStyleSheet(blendedStyle);
308 recentDocumentsLabel->setStyleSheet(blendedStyle);
309 helpTitleLabel->setStyleSheet(blendedStyle);
310 newsTitleLabel->setStyleSheet(blendedStyle);
311 newFileLinkShortcut->setStyleSheet(blendedStyle);
312 openFileShortcut->setStyleSheet(blendedStyle);
313 clearRecentFilesLink->setStyleSheet(blendedStyle);
314 recentDocumentsListView->setStyleSheet(blendedStyle);
315 newsWidget->setStyleSheet(blendedStyle);
316
317#ifdef Q_OS_ANDROID
318 blendedStyle = blendedStyle + "\nQPushButton { padding: 10px }";
319#endif
320
321 newFileLink->setStyleSheet(blendedStyle);
322 openFileLink->setStyleSheet(blendedStyle);
323
324 // make drop area QFrame have a dotted line
325 dropFrameBorder->setObjectName("dropAreaIndicator");
326 QString dropFrameStyle = QString("QFrame#dropAreaIndicator { border: 4px dotted ").append(blendedColor.name()).append("}");
327 dropFrameBorder->setStyleSheet(dropFrameStyle);
328
329 // only show drop area when we have a document over the empty area
331
332 // add icons for new and open settings to make them stand out a bit more
333 openFileLink->setIconSize(QSize(48, 48));
334 newFileLink->setIconSize(QSize(48, 48));
335
336 openFileLink->setIcon(KisIconUtils::loadIcon("document-open"));
337 newFileLink->setIcon(KisIconUtils::loadIcon("document-new"));
338
339 btnNewsOptions->setIcon(KisIconUtils::loadIcon("view-choose"));
340 btnNewsOptions->setFlat(true);
341
342 notifyIcon->setIcon(KisIconUtils::loadIcon("notification-dot"));
343
344 supportKritaIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("support-krita")));
345 userManualIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("help-contents")));
346 gettingStartedIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("get_started")));
347 userCommunityIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("comunity")));
348 kritaWebsiteIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("website")));
349 sourceCodeIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("code")));
350 kdeIcon->setIcon(KisIconUtils::loadIcon(QStringLiteral("kde")));
351
352 // HTML links seem to be a bit more stubborn with theme changes... setting inline styles to help with color change
353 userCommunityLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://krita-artists.org\">")
354 .append(i18n("User Community")).append("</a>"));
355
356 gettingStartedLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://docs.krita.org/user_manual/getting_started.html\">")
357 .append(i18n("Getting Started")).append("</a>"));
358
359 manualLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://docs.krita.org\">")
360 .append(i18n("User Manual")).append("</a>"));
361
362 supportKritaLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://krita.org/support-us/donations?" + analyticsString + "donations" + "\">")
363 .append(i18n("Support Krita")).append("</a>"));
364
365 kritaWebsiteLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://www.krita.org?" + analyticsString + "marketing-site" + "\">")
366 .append(i18n("Krita Website")).append("</a>"));
367
368 sourceCodeLink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://invent.kde.org/graphics/krita\">")
369 .append(i18n("Source Code")).append("</a>"));
370
371 poweredByKDELink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://userbase.kde.org/What_is_KDE\">")
372 .append(i18n("Powered by KDE")).append("</a>"));
373
374 const QColor frameColor = KisPaintingTweaks::blendColors(textColor, backgroundColor, 0.1);
375 const QString &frameQss = "{border: 1px solid " + frameColor.name() + "}";
376 recentDocsStackedWidget->setStyleSheet("QStackedWidget#recentDocsStackedWidget" + frameQss);
377 newsFrame->setStyleSheet("QFrame#newsFrame" + frameQss);
378
379 // show the dev version labels, if dev version is detected
381
382#ifdef ENABLE_UPDATERS
383 updateVersionUpdaterFrame(); // updater frame
384#endif
385
386#ifdef Q_OS_MACOS
387 // macOS store version should not contain external links containing donation buttons or forms
388 if (KisMacosEntitlements().sandbox()) {
389 supportKritaLink->hide();
390 supportKritaIcon->hide();
391 labelSupportText->hide();
392 kritaWebsiteLink->hide();
393 kritaWebsiteIcon->hide();
394 }
395#endif
396}
397
398void KisWelcomePageWidget::dragEnterEvent(QDragEnterEvent *event)
399{
401 if (event->mimeData()->hasUrls() ||
402 event->mimeData()->hasFormat("application/x-krita-node-internal-pointer") ||
403 event->mimeData()->hasFormat("application/x-qt-image")) {
404 return event->accept();
405 }
406
407 return event->ignore();
408}
409
410void KisWelcomePageWidget::dropEvent(QDropEvent *event)
411{
413
414 if (event->mimeData()->hasUrls() && !event->mimeData()->urls().empty()) {
415 Q_FOREACH (const QUrl &url, event->mimeData()->urls()) {
416 if (url.toLocalFile().endsWith(".bundle", Qt::CaseInsensitive)) {
417 bool r = m_mainWindow->installBundle(url.toLocalFile());
418 if (!r) {
419 qWarning() << "Could not install bundle" << url.toLocalFile();
420 }
421 } else if (!url.isLocalFile()) {
422 QScopedPointer<QTemporaryFile> tmp(new QTemporaryFile());
423 tmp->setFileName(url.fileName());
424
425 KisRemoteFileFetcher fetcher;
426
427 if (!fetcher.fetchFile(url, tmp.data())) {
428 qWarning() << "Fetching" << url << "failed";
429 continue;
430 }
431 const auto localUrl = QUrl::fromLocalFile(tmp->fileName());
432
433 m_mainWindow->openDocument(localUrl.toLocalFile(), KisMainWindow::None);
434 } else {
435 m_mainWindow->openDocument(url.toLocalFile(), KisMainWindow::None);
436 }
437 }
438 }
439}
440
441void KisWelcomePageWidget::dragMoveEvent(QDragMoveEvent *event)
442{
444
445 if (event->mimeData()->hasUrls() ||
446 event->mimeData()->hasFormat("application/x-krita-node-internal-pointer") ||
447 event->mimeData()->hasFormat("application/x-qt-image")) {
448 return event->accept();
449 }
450
451 return event->ignore();
452}
453
454void KisWelcomePageWidget::dragLeaveEvent(QDragLeaveEvent */*event*/)
455{
458}
459
461{
462 if (event->type() == QEvent::FontChange) {
463 labelSupportText->setFont(largerFont());
464 }
465}
466
467bool KisWelcomePageWidget::eventFilter(QObject *watched, QEvent *event)
468{
469 if (watched == recentDocumentsListView && event->type() == QEvent::Leave) {
470 recentDocumentsListView->clearSelection();
471 }else if (watched == recentDocumentsListView && event->type() == QEvent::Resize) {
473 }
474 return QWidget::eventFilter(watched, event);
475}
476
477namespace {
478
479QString getAutoNewsLang()
480{
481 // Get current UI languages:
482 const QStringList uiLangs = KLocalizedString::languages();
483 QString autoNewsLang = uiLangs.first();
484 if (autoNewsLang.isEmpty()) {
485 // If nothing else, use English.
486 autoNewsLang = QString("en");
487 } else if (autoNewsLang == "jp") {
488 return QString("ja");
489 } else if (autoNewsLang == "zh_CN") {
490 return QString("zh-cn");
491 } else if (autoNewsLang == "zh_TW") {
492 return QString("zh-tw");
493 } else if (autoNewsLang == "zh_HK") {
494 return QString("zh-hk");
495 } else if (autoNewsLang == "en" || autoNewsLang == "en_US" || autoNewsLang == "en_GB") {
496 return QString("en");
497 }
498
499 return autoNewsLang;
500}
501
502} /* namespace */
503
505{
506 // Hard-coded news language data:
507 // These are languages in which the news items should be regularly
508 // translated into as of 04-09-2024.
509 // The language display names should not be translated. This reflects
510 // the language selection box on the Krita website.
511 struct Lang {
512 const QString siteCode;
513 const QString name;
514 };
515 static const std::array<Lang, 22> newsLangs = {{
516 {QString("en"), QStringLiteral("English")},
517 {QString("ja"), QStringLiteral("日本語")},
518 {QString("zh-cn"), QStringLiteral("中文 (简体)")},
519 {QString("zh-tw"), QStringLiteral("中文 (台灣正體)")},
520 {QString("zh-hk"), QStringLiteral("廣東話 (香港)")},
521 {QString("ca"), QStringLiteral("Català")},
522 {QString("ca@valencia"), QStringLiteral("Català de Valencia")},
523 {QString("cs"), QStringLiteral("Čeština")},
524 {QString("de"), QStringLiteral("Deutsch")},
525 {QString("eo"), QStringLiteral("Esperanto")},
526 {QString("es"), QStringLiteral("Español")},
527 {QString("eu"), QStringLiteral("Euskara")},
528 {QString("fr"), QStringLiteral("Français")},
529 {QString("it"), QStringLiteral("Italiano")},
530 {QString("lt"), QStringLiteral("lietuvių")},
531 {QString("nl"), QStringLiteral("Nederlands")},
532 {QString("pt"), QStringLiteral("Português")},
533 {QString("sk"), QStringLiteral("Slovenský")},
534 {QString("sl"), QStringLiteral("Slovenski")},
535 {QString("sv"), QStringLiteral("Svenska")},
536 {QString("tr"), QStringLiteral("Türkçe")},
537 {QString("uk"), QStringLiteral("Українська")}
538 }};
539
540 static const QString newsLangConfigName = QStringLiteral("FetchNewsLanguages");
541
542 QSharedPointer<QSet<QString>> enabledNewsLangs = QSharedPointer<QSet<QString>>::create();
543 {
544 // Initialize with the config.
545 KisConfig cfg(true);
546 auto languagesList = cfg.readList<QString>(newsLangConfigName);
547 *enabledNewsLangs = QSet(languagesList.begin(), languagesList.end());
548 }
549
550 // If no languages are selected in the config, use the automatic selection.
551 if (enabledNewsLangs->isEmpty()) {
552 enabledNewsLangs->insert(QString(getAutoNewsLang()));
553 }
554
555 for (const auto &lang : newsLangs) {
556 QAction *langItem = newsOptionsMenu->addAction(lang.name);
557 langItem->setCheckable(true);
558 // We can copy `code` into the lambda because its backing string is a
559 // static string literal.
560 const QString code = lang.siteCode;
561 connect(langItem, &QAction::toggled, newsWidget, [=](bool checked) {
562 newsWidget->toggleNewsLanguage(code, checked);
563 });
564
565 // Set the initial checked state.
566 if (enabledNewsLangs->contains(code)) {
567 langItem->setChecked(true);
568 }
569
570 // Connect this lambda after setting the initial checked state because
571 // we don't want to overwrite the config when doing the initial setup.
572 connect(langItem, &QAction::toggled, qApp, [=](bool checked) {
573 KisConfig cfg(false);
574 // It is safe to modify `enabledNewsLangs` here, because the slots
575 // are called synchronously on the UI thread so there is no need
576 // for explicit synchronization.
577 if (checked) {
578 enabledNewsLangs->insert(QString(code));
579 } else {
580 enabledNewsLangs->remove(QString(code));
581 }
582 cfg.writeList(newsLangConfigName, enabledNewsLangs->values());
583 });
584 }
585}
586
588{
589 // always flag development version
590 if (isDevelopmentBuild()) {
591 QString devBuildLabelText = QString("<a style=\"color: " +
592 blendedColor.name() +
593 " \" href=\"https://docs.krita.org/en/untranslatable_pages/triaging_bugs.html?"
594 + analyticsString + "dev-build" + "\">")
595 .append(i18n("DEV BUILD")).append("</a>");
596
597 devBuildLabel->setText(devBuildLabelText);
598 devBuildIcon->setVisible(true);
599 devBuildLabel->setVisible(true);
600 } else {
601 devBuildIcon->setVisible(false);
602 devBuildLabel->setVisible(false);
603 }
604}
605
606void KisWelcomePageWidget::updateShortcutLink(QToolButton *button, QLabel *label, QAction *action)
607{
608 if (action) {
609 QString shortcutText = action->shortcut().toString(QKeySequence::NativeText);
610 if (shortcutText.isEmpty()) {
611 label->setText(QString());
612 } else {
613 label->setText(QStringLiteral("(%1)").arg(shortcutText));
614 }
615 button->show();
616 label->show();
617 } else {
618 button->hide();
619 label->hide();
620 }
621}
622
624{
625 QString fileUrl = index.data(Qt::ToolTipRole).toString();
627}
628
630{
631 QMenu contextMenu;
632 QModelIndex index = recentDocumentsListView->indexAt(pos);
633 QAction *actionForget = 0;
634 if (index.isValid()) {
635 actionForget = new QAction(i18n("Forget \"%1\"", index.data(Qt::DisplayRole).toString()), &contextMenu);
636 contextMenu.addAction(actionForget);
637 }
638 QAction *triggered = contextMenu.exec(recentDocumentsListView->mapToGlobal(pos));
639
640 if (index.isValid() && triggered == actionForget) {
641 m_mainWindow->removeRecentFile(index.data(Qt::ToolTipRole).toString());
642 }
643}
644
649
654
659
661{
662 if (!this->isVisible())
663 return;
664
665 // Don't do anything if there's no image in the clipboard
666 if (!KisClipboard::instance()->hasImage())
667 return;
668
670
672 dlg->exec();
673 dlg->deleteLater();
674}
675
677{
679 const bool modelIsEmpty = recentFilesModel->model().rowCount() == 0;
680
681 if (modelIsEmpty) {
682 recentDocsStackedWidget->setCurrentWidget(labelNoRecentDocs);
683 } else {
684 recentDocsStackedWidget->setCurrentWidget(recentDocumentsListView);
685 }
686 clearRecentFilesLink->setVisible(!modelIsEmpty);
687}
688
690{
691 enableNewsBox->setChecked(newsEnabled);
692 m_enableNewsAction->setChecked(newsEnabled);
693 KisConfig(false).setNewsCheckEnabled(newsEnabled);
694}
695
697{
698 checkNowButton->setEnabled(false);
699 noNewsWidget->hide();
700 newsWidget->show();
701 newsWidget->toggleNews(true);
702#ifdef ENABLE_UPDATERS
703 if (m_versionUpdater) {
704 m_versionUpdater->checkForUpdate();
705 updateVersionUpdaterFrame();
706 }
707#endif
708}
709
710#ifdef ENABLE_UPDATERS
711void KisWelcomePageWidget::slotRunVersionUpdate()
712{
713 if (!m_versionUpdater.isNull()) {
714 m_versionUpdater->doUpdate();
715 }
716}
717
718void KisWelcomePageWidget::slotSetUpdateStatus(KisUpdaterStatus updateStatus)
719{
720 m_updaterStatus = updateStatus;
721 updateVersionUpdaterFrame();
722}
723
724void KisWelcomePageWidget::slotShowUpdaterErrorDetails()
725{
726 QMessageBox::warning(qApp->activeWindow(), i18nc("@title:window", "Krita"), m_updaterStatus.updaterOutput());
727}
728
729void KisWelcomePageWidget::updateVersionUpdaterFrame()
730{
731 updaterFrame->setVisible(false);
732 versionNotificationLabel->setVisible(false);
733 versionNotificationLabel->setEnabled(false);
734 updateWidget->setVisible(false);
735 bnVersionUpdate->setVisible(false);
736 bnErrorDetails->setVisible(false);
737
738 if (m_versionUpdater.isNull()) {
739 return;
740 }
741
742 QString versionLabelText;
743
744 if (m_updaterStatus.status() == UpdaterStatus::StatusID::UPDATE_AVAILABLE) {
745 updaterFrame->setVisible(true);
746 updaterFrame->setEnabled(true);
747 versionLabelText = i18n("New version of Krita is available.");
748 versionNotificationLabel->setEnabled(true);
749 versionNotificationLabel->setVisible(true);
750 updateIcon->setIcon(KisIconUtils::loadIcon("update-medium"));
751
752 if (m_versionUpdater->hasUpdateCapability()) {
753 bnVersionUpdate->setVisible(true);
754 updateWidget->setVisible(true);
755 } else {
756 // build URL for label
757 QString downloadLink = QString(" <a style=\"color: %1; text-decoration: underline\" href=\"%2?%3\">Download Krita %4</a>")
758 .arg(blendedColor.name())
759 .arg(m_updaterStatus.downloadLink())
760 .arg(analyticsString + "version-update")
761 .arg(m_updaterStatus.availableVersion());
762
763 versionLabelText.append(downloadLink);
764 }
765
766 } else if (
767 (m_updaterStatus.status() == UpdaterStatus::StatusID::UPTODATE)
768 || (m_updaterStatus.status() == UpdaterStatus::StatusID::CHECK_ERROR)
769 || (m_updaterStatus.status() == UpdaterStatus::StatusID::IN_PROGRESS)
770 ){
771 // no notifications, if uptodate
772 // also, stay silent on check error - we do not want to generate lots of user support issues
773 // because of failing wifis and proxies over the world
774 updaterFrame->setVisible(false);
775
776 } else if (m_updaterStatus.status() == UpdaterStatus::StatusID::UPDATE_ERROR) {
777 updaterFrame->setVisible(true);
778 versionLabelText = i18n("An error occurred during the update");
779 versionNotificationLabel->setVisible(true);
780 bnErrorDetails->setVisible(true);
781 updateWidget->setVisible(true);
782 updateIcon->setIcon(KisIconUtils::loadIcon("warning"));
783 } else if (m_updaterStatus.status() == UpdaterStatus::StatusID::RESTART_REQUIRED) {
784 updaterFrame->setVisible(true);
785 versionLabelText = QString("<b>%1</b> %2").arg(i18n("Restart is required.")).arg(m_updaterStatus.details());
786 versionNotificationLabel->setVisible(true);
787 updateIcon->setIcon(KisIconUtils::loadIcon("view-refresh"));
788 }
789
790 versionNotificationLabel->setText(versionLabelText);
791 if (!blendedStyle.isNull()) {
792 versionNotificationLabel->setStyleSheet(blendedStyle);
793 }
794}
795#endif
796
797#ifdef Q_OS_ANDROID
798void KisWelcomePageWidget::initDonations()
799{
801 if (!androidDonations) {
802 qWarning("KisWelcomePage::initDonations: androidDonations is null");
803 return;
804 }
805
806 // Pick a random banner. Note that the second number is *exclusive*.
807 int bannerIndex = QRandomGenerator::global()->bounded(1, 5);
808
809 // Banners have space where we can place text, but this varies by banner.
810 // These are the relative locations where that space is.
811 qreal ry = 0.02; // Vertical offset, always the same.
812 qreal rh = 1.0 - ry * 2.0; // Height, dito.
813 qreal rwpad = 0.02; // Horizontal padding.
814 qreal rx, rw; // Horizontal offset and width, vary by banner.
815 switch (bannerIndex) {
816 case 1: // Kiki winking on the left.
817 case 3: // Stargazers on the left.
818 rx = 0.4;
819 rw = 1.0 - rx - rwpad;
820 break;
821 case 2: // Cat holding brush in its mouth on the right.
822 case 4: // Person holding digital palette on the right.
823 rx = rwpad;
824 rw = 0.6 - rx;
825 break;
826 default: // Shouldn't happen, punt to using the entire width minus padding.
827 qWarning("Unhandled banner index %d", bannerIndex);
828 rx = rwpad;
829 rw = 1.0 - rwpad * 2.0;
830 break;
831 }
832
833 QString welcomeBannerPath =
834 QStandardPaths::locate(QStandardPaths::AppDataLocation,
835 QStringLiteral("share/krita/donation/welcomebanner%1.jpg").arg(bannerIndex));
836 QPixmap welcomeBannerPixmap(welcomeBannerPath);
837
838 if (welcomeBannerPixmap.isNull()) {
839 qWarning("KisWelcomePage::initDonations: failed to load welcome banner from '%s'",
840 qUtf8Printable(welcomeBannerPath));
841 // Leave the button alone, it will just say "Support Krita!"
842 } else {
843 QVector<QString> headlines = {
844 i18n("Become a Supporter!"),
845 i18n("Support Krita!"),
846 };
847 QVector<QString> subtitles = {
848 i18n("Supporters get brush packs and more."),
849 i18n("Contributions keep development going."),
850 };
851 QString headline = headlines[QRandomGenerator::global()->bounded(headlines.size())];
852 QString subtitle = subtitles[QRandomGenerator::global()->bounded(subtitles.size())];
853
854 // We want some text on the banner, which unfortunately requires some
855 // manual layout. We're going to write a top line in a larger font and
856 // a bottom line in a smaller font. They're going to be separated by a
857 // few pixels, centered horizontally and fit into predefined bounds on
858 // the banner depending on which image we're using. The text will be
859 // white with a black outline, so we'll use QPainterPath. Math time.
860 QPainter painter(&welcomeBannerPixmap);
861 painter.setRenderHint(QPainter::Antialiasing);
862 painter.setRenderHint(QPainter::TextAntialiasing);
863
864 QPen pen(Qt::black, 12.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
865 QBrush brush(Qt::white);
866
867 qreal verticalSeparation = 40.0;
868
869 // Top line, the heading.
870 QFont currentFont = font();
871 currentFont.setPointSize(100);
872 currentFont.setBold(false);
873 QPainterPath topPath;
874 topPath.addText(0, 0, currentFont, headline);
875 QRectF topBounds = topPath.boundingRect();
876
877 // Bottom line, smaller text for more words.
878 currentFont.setPointSize(60);
879 currentFont.setBold(true);
880 QPainterPath bottomPath;
881 bottomPath.addText(0, 0, currentFont, subtitle);
882 QRectF bottomBounds = bottomPath.boundingRect();
883
884 // Stick those two lines into a combined path, horizontally centered,
885 // separated a bit so that the text doesn't get glued together.
886 qreal maxWidth = qMax(topBounds.width(), bottomBounds.width());
887 qreal topOffsetX = (maxWidth - topBounds.width()) / 2.0;
888 qreal bottomOffsetX = (maxWidth - bottomBounds.width()) / 2.0;
889
890 QTransform topTransform;
891 topTransform.translate(topOffsetX - topBounds.left(), -topBounds.top());
892 topPath = topTransform.map(topPath);
893 topPath.setFillRule(Qt::WindingFill);
894
895 QTransform bottomTransform;
896 bottomTransform.translate(bottomOffsetX - bottomBounds.left(),
897 topBounds.height() + verticalSeparation - bottomBounds.top());
898 bottomPath = bottomTransform.map(bottomPath);
899 bottomPath.setFillRule(Qt::WindingFill);
900
901 QPainterPath combinedPath;
902 combinedPath.addPath(topPath);
903 combinedPath.addPath(bottomPath);
904
905 // Determine the rectangle on the banner that we want to fit the text
906 // into. Taking a detour through the paint device just in case high-DPI
907 // scaling messes with the dimensions somehow.
908 qreal w = painter.device()->width();
909 qreal h = painter.device()->height();
910 QRect rect(w * rx, h * ry, w * rw, h * rh);
911
912 QRectF combinedBounds = combinedPath.boundingRect();
913 qreal scaleX = rect.width() / combinedBounds.width();
914 qreal scaleY = rect.height() / combinedBounds.height();
915 qreal scale = qMin(scaleX, scaleY);
916 qreal combinedOffsetX = (rect.width() - (combinedBounds.width() * scale)) / 2.0;
917 qreal combinedOffsetY = (rect.height() - (combinedBounds.height() * scale)) / 2.0;
918
919 QTransform combinedTransform;
920 combinedTransform.translate(rect.left() + combinedOffsetX, rect.top() + combinedOffsetY);
921 combinedTransform.scale(scale, scale);
922 combinedTransform.translate(-combinedBounds.left(), -combinedBounds.top());
923 combinedPath = combinedTransform.map(combinedPath);
924 combinedPath.setFillRule(Qt::WindingFill);
925
926 // And finally, draw the text onto the banner. First stroking the
927 // outside, then filling the inside, otherwise there's weird effects
928 // with strokes inside of letters overlapping with the fill.
929 painter.setPen(pen);
930 painter.setBrush(Qt::NoBrush);
931 painter.drawPath(combinedPath);
932
933 painter.setPen(Qt::NoPen);
934 painter.setBrush(brush);
935 painter.drawPath(combinedPath);
936
937 QSize welcomeBannerSize = welcomeBannerPixmap.size().scaled(500, 100, Qt::KeepAspectRatio);
938 bnAndroidSupport->setFlat(false);
939 bnAndroidSupport->setText(QString());
940 bnAndroidSupport->setContentsMargins(0, 0, 0, 0);
941 bnAndroidSupport->setIcon(QIcon(welcomeBannerPixmap));
942 bnAndroidSupport->setIconSize(welcomeBannerSize);
943 bnAndroidSupport->setFixedSize(welcomeBannerSize);
944 }
945
946 connect(bnAndroidSupport, &QPushButton::clicked, androidDonations, &KisAndroidDonations::slotStartDonationFlow);
947 connect(bnAndroidSupporterManage,
948 &QPushButton::clicked,
949 androidDonations,
951
952 QString badgePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, "share/krita/donation/banner.png");
953 QPixmap badgePixmap(badgePath);
954 if (badgePixmap.isNull()) {
955 qWarning("KisWelcomePage::initDonations: failed to load badge from '%s'", qUtf8Printable(badgePath));
956 } else {
957 supporterBadge->setPixmap(badgePixmap);
958 }
959
960 connect(androidDonations, SIGNAL(sigStateChanged()), this, SLOT(slotUpdateDonationState()));
961 slotUpdateDonationState();
962}
963
964void KisWelcomePageWidget::slotUpdateDonationState()
965{
966 bool badgeVisible = false;
967 QWidget *pageVisible = pgSupportMessage;
968
970 if (androidDonations) {
971 badgeVisible = androidDonations->shouldShowSupporterBadge();
972 switch (androidDonations->state()) {
974 pageVisible = pgAndroidSupporter;
975 break;
977 pageVisible = nullptr;
978 break;
979 default:
980 break;
981 }
982 } else {
983 qWarning("KisWelcomePageWidget::slotUpdateDonationState: android donations is null");
984 }
985
986 if(pageVisible) {
987 stkSupport->setCurrentWidget(pageVisible);
988 wdgAndroidSupportBanner->hide();
989 stkSupport->show();
990 } else {
991 stkSupport->hide();
992 wdgAndroidSupportBanner->show();
993 }
994
995 supporterBadge->setVisible(badgeVisible);
996}
997#endif
998
1000{
1001 QFont larger = font();
1002 // Font size may be in pixels (on Android) or points (everywhere else.)
1003 qreal ratio = 1.1;
1004 if (larger.pixelSize() == -1) {
1005 larger.setPointSizeF(larger.pointSizeF() * ratio);
1006 } else {
1007 larger.setPixelSize(qRound(larger.pixelSize() * ratio));
1008 }
1009 return larger;
1010}
1011
1013{
1014 int scrollSize = qApp->style()->pixelMetric(QStyle::PM_SliderThickness);
1015 int spacing = 8;
1016
1018
1019 int currentSize = recentDocumentsListView->size().width()-scrollSize-2;
1020 int iconAmount = floor(currentSize/iconLength);
1021 int length = floor(currentSize / iconAmount)-spacing;
1022
1023 recentDocumentsListView->setIconSize(QSize(length,length));
1024}
1025
1027{
1028 btnDismisAll->setVisible(hasNews);
1029 notifyIcon->setVisible(hasNews);
1030
1031
1032 //colapse or expand notifyIcon and btnDismisAll
1033
1034 QSizePolicy sizePolicy = notifyIcon->sizePolicy();
1035 if (hasNews) {
1036 sizePolicy.setHorizontalPolicy(QSizePolicy::Preferred);
1037 } else {
1038 sizePolicy.setHorizontalPolicy(QSizePolicy::Ignored);
1039 }
1040 notifyIcon->setSizePolicy(sizePolicy);
1041
1042 //notifyIcon and btnDismisAll should both have the same size policy
1043 btnDismisAll->setSizePolicy(sizePolicy);
1044}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
KisAction * actionByName(const QString &name) const
bool shouldShowSupporterBadge() const
static KisAndroidDonations * instance()
void sigShowDonationManagementDialogRequested()
static KisClipboard * instance()
void writeList(const QString &name, const QList< T > &value)
Definition kis_config.h:909
QList< T > readList(const QString &name, const QList< T > &defaultValue=QList< T >())
Definition kis_config.h:919
bool newsFirstStartup() const
void setNewsCheckEnabled(bool value)
void setNewsFirstStartup(bool value)
bool newsCheckEnabled() const
Main window for Krita.
bool installBundle(const QString &fileName) const
Copy the given file into the bundle directory.
bool openDocument(const QString &path, OpenFlags flags)
KisViewManager * viewManager
void slotFileOpen(bool isImporting=false)
void removeRecentFile(QString url)
void dragMoveEvent(QDragMoveEvent *event) override
static constexpr const int DEFALT_ICON_SIZE_LENGTH
static KisRecentDocumentsModelWrapper * instance()
The KisRemoteFileFetcher class can fetch a remote file and blocks until the file is downloaded.
bool fetchFile(const QUrl &remote, QIODevice *io)
fetch the image. Shows a progress dialog
static void log(const QString &message)
Logs with date/time.
KisActionManager * actionManager() const
void recentDocumentClicked(QModelIndex index)
KisWelcomePageWidget(QWidget *parent)
void dragEnterEvent(QDragEnterEvent *event) override
void slotSetNewsEnabled(bool newsEnabled)
void setupNewsLangSelection(QMenu *newsOptionMenu)
bool eventFilter(QObject *watched, QEvent *event) override
static void updateShortcutLink(QToolButton *button, QLabel *label, QAction *action)
void dropEvent(QDropEvent *event) override
void slotScrollerStateChanged(QScroller::State state)
void newsStateChanged(bool hasNews)
void dragLeaveEvent(QDragLeaveEvent *event) override
void changeEvent(QEvent *event) override
void setMainWindow(KisMainWindow *m_mainWindow)
void slotRecentDocContextMenuRequest(const QPoint &pos)
void showDropAreaIndicator(bool show)
void dragMoveEvent(QDragMoveEvent *event) override
RecentItemDelegate(QObject *parent=0)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const override
void setItemHeight(int itemHeight)
QString button(const QWheelEvent &ev)
QIcon loadIcon(const QString &name)
void updateIcon(QAbstractButton *button)
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)
QColor blendColors(const QColor &c1, const QColor &c2, qreal r1)
KRITAVERSION_EXPORT bool isDevelopersBuild()