diff --git a/libs/ui/KisMultiFeedRSSModel.cpp b/libs/ui/KisMultiFeedRSSModel.cpp index 20c93ef791..a5cf9b76b6 100644 --- a/libs/ui/KisMultiFeedRSSModel.cpp +++ b/libs/ui/KisMultiFeedRSSModel.cpp @@ -1,221 +1,221 @@ /************************************************************************** ** ** This file is part of Qt Creator ** ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). ** ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** ** GNU Lesser General Public License Usage ** ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this file. ** Please review the following information to ensure the GNU Lesser General ** Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** Other Usage ** ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** **************************************************************************/ #include "KisMultiFeedRSSModel.h" #include #include #include #include #include #include #include #include QString shortenHtml(QString html) { html.replace(QLatin1String("")); uint firstParaEndHtml = (uint) html.indexOf(QLatin1String("

"), html.indexOf(QLatin1String("

"))+1); uint firstParaEndBr = (uint) html.indexOf(QLatin1String("request().url(); requestUrl = source.toString(); streamReader.setDevice(reply); RssItemList list; while (!streamReader.atEnd()) { switch (streamReader.readNext()) { case QXmlStreamReader::StartElement: if (streamReader.name() == QLatin1String("item")) list.append(parseItem()); else if (streamReader.name() == QLatin1String("title")) blogName = streamReader.readElementText(); else if (streamReader.name() == QLatin1String("link")) { if (!streamReader.namespaceUri().isEmpty()) break; QString favIconString(streamReader.readElementText()); QUrl favIconUrl(favIconString); favIconUrl.setPath(QLatin1String("favicon.ico")); blogIcon = favIconUrl.toString(); blogIcon = QString(); // XXX: fix the favicon on krita.org! } break; default: break; } } return list; } private: QXmlStreamReader streamReader; QString requestUrl; QString blogIcon; QString blogName; }; MultiFeedRssModel::MultiFeedRssModel(QObject *parent) : QAbstractListModel(parent), m_networkAccessManager(new KisNetworkAccessManager), m_articleCount(0) { connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), SLOT(appendFeedData(QNetworkReply*)), Qt::QueuedConnection); } MultiFeedRssModel::~MultiFeedRssModel() { } QHash MultiFeedRssModel::roleNames() const { QHash roleNames; roleNames[TitleRole] = "title"; roleNames[DescriptionRole] = "description"; roleNames[PubDateRole] = "pubDate"; roleNames[LinkRole] = "link"; roleNames[BlogNameRole] = "blogName"; roleNames[BlogIconRole] = "blogIcon"; return roleNames; } void MultiFeedRssModel::addFeed(const QString& feed) { const QUrl feedUrl(feed); QMetaObject::invokeMethod(m_networkAccessManager, "getUrl", Qt::QueuedConnection, Q_ARG(QUrl, feedUrl)); } bool sortForPubDate(const RssItem& item1, const RssItem& item2) { return item1.pubDate > item2.pubDate; } void MultiFeedRssModel::appendFeedData(QNetworkReply *reply) { RssReader reader; m_aggregatedFeed.append(reader.parse(reply)); std::sort(m_aggregatedFeed.begin(), m_aggregatedFeed.end(), sortForPubDate); setArticleCount(m_aggregatedFeed.size()); beginResetModel(); endResetModel(); } void MultiFeedRssModel::removeFeed(const QString &feed) { QMutableListIterator it(m_aggregatedFeed); while (it.hasNext()) { RssItem item = it.next(); if (item.source == feed) it.remove(); } setArticleCount(m_aggregatedFeed.size()); } int MultiFeedRssModel::rowCount(const QModelIndex &) const { return m_aggregatedFeed.size(); } QVariant MultiFeedRssModel::data(const QModelIndex &index, int role) const { RssItem item = m_aggregatedFeed.at(index.row()); switch (role) { case Qt::DisplayRole: { - return QString("" + item.title + "" - "

" + item.pubDate.toString("dd-MM-yyyy hh:mm") + "

" - "

" + item.description + "


"); + return QString("" + item.title + "" + "

" + item.pubDate.toString("MMMM d, yyyy hh:mm") + "

" + "

" + item.description.left(70).append("...") + "


"); } case TitleRole: return item.title; case DescriptionRole: return item.description; case PubDateRole: return item.pubDate.toString("dd-MM-yyyy hh:mm"); case LinkRole: return item.link; case BlogNameRole: return item.blogName; case BlogIconRole: return item.blogIcon; } return QVariant(); } diff --git a/libs/ui/KisWelcomePageWidget.cpp b/libs/ui/KisWelcomePageWidget.cpp index fa4b6316ec..22950a0796 100644 --- a/libs/ui/KisWelcomePageWidget.cpp +++ b/libs/ui/KisWelcomePageWidget.cpp @@ -1,278 +1,285 @@ /* This file is part of the KDE project * Copyright (C) 2018 Scott Petrovic * * 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 "KisWelcomePageWidget.h" #include #include #include "kis_action_manager.h" #include "kactioncollection.h" #include "kis_action.h" #include "KConfigGroup" #include "KSharedConfig" #include #include #include "kis_icon_utils.h" #include "krita_utils.h" #include "KoStore.h" - +#include "kis_config.h" KisWelcomePageWidget::KisWelcomePageWidget(QWidget *parent) : QWidget(parent) { setupUi(this); recentDocumentsListView->viewport()->setAutoFillBackground(false); recentDocumentsListView->setSpacing(2); + + connect(chkShowNews, SIGNAL(toggled(bool)), newsWidget, SLOT(toggleNews(bool))); + + // configure the News area + KisConfig cfg(true); + bool m_getNews = cfg.readEntry("FetchNews", false); + chkShowNews->setChecked(m_getNews); + } KisWelcomePageWidget::~KisWelcomePageWidget() { } void KisWelcomePageWidget::setMainWindow(KisMainWindow* mainWin) { if (mainWin) { mainWindow = mainWin; - // set the shortcut links from actions (only if a shortcut exists) if ( mainWin->viewManager()->actionManager()->actionByName("file_new")->shortcut().toString() != "") { newFileLinkShortcut->setText(QString("(") + mainWin->viewManager()->actionManager()->actionByName("file_new")->shortcut().toString() + QString(")")); } if (mainWin->viewManager()->actionManager()->actionByName("file_open")->shortcut().toString() != "") { openFileShortcut->setText(QString("(") + mainWin->viewManager()->actionManager()->actionByName("file_open")->shortcut().toString() + QString(")")); } populateRecentDocuments(); connect(recentDocumentsListView, SIGNAL(clicked(QModelIndex)), this, SLOT(recentDocumentClicked(QModelIndex))); // we need the view manager to actually call actions, so don't create the connections // until after the view manager is set connect(newFileLink, SIGNAL(clicked(bool)), this, SLOT(slotNewFileClicked())); connect(openFileLink, SIGNAL(clicked(bool)), this, SLOT(slotOpenFileClicked())); // URL link connections connect(manualLink, SIGNAL(clicked(bool)), this, SLOT(slotGoToManual())); connect(gettingStartedLink, SIGNAL(clicked(bool)), this, SLOT(slotGettingStarted())); connect(supportKritaLink, SIGNAL(clicked(bool)), this, SLOT(slotSupportKrita())); connect(userCommunityLink, SIGNAL(clicked(bool)), this, SLOT(slotUserCommunity())); connect(kritaWebsiteLink, SIGNAL(clicked(bool)), this, SLOT(slotKritaWebsite())); connect(sourceCodeLink, SIGNAL(clicked(bool)), this, SLOT(slotSourceCode())); connect(clearRecentFilesLink, SIGNAL(clicked(bool)), this, SLOT(slotClearRecentFiles())); connect(poweredByKDELink, SIGNAL(clicked(bool)), this, SLOT(slotKDESiteLink())); slotUpdateThemeColors(); } } void KisWelcomePageWidget::showDropAreaIndicator(bool show) { if (!show) { QString dropFrameStyle = "QFrame#dropAreaIndicator { border: 0px }"; dropFrameBorder->setStyleSheet(dropFrameStyle); } else { QColor textColor = qApp->palette().color(QPalette::Text); QColor backgroundColor = qApp->palette().color(QPalette::Background); QColor blendedColor = KritaUtils::blendColors(textColor, backgroundColor, 0.8); // QColor.name() turns it into a hex/web format QString dropFrameStyle = QString("QFrame#dropAreaIndicator { border: 2px dotted ").append(blendedColor.name()).append(" }") ; dropFrameBorder->setStyleSheet(dropFrameStyle); } } void KisWelcomePageWidget::slotUpdateThemeColors() { QColor textColor = qApp->palette().color(QPalette::Text); QColor backgroundColor = qApp->palette().color(QPalette::Background); // make the welcome screen labels a subtle color so it doesn't clash with the main UI elements QColor blendedColor = KritaUtils::blendColors(textColor, backgroundColor, 0.8); QString blendedStyle = QString("color: ").append(blendedColor.name()); // what labels to change the color... startTitleLabel->setStyleSheet(blendedStyle); recentDocumentsLabel->setStyleSheet(blendedStyle); helpTitleLabel->setStyleSheet(blendedStyle); manualLink->setStyleSheet(blendedStyle); gettingStartedLink->setStyleSheet(blendedStyle); supportKritaLink->setStyleSheet(blendedStyle); userCommunityLink->setStyleSheet(blendedStyle); kritaWebsiteLink->setStyleSheet(blendedStyle); sourceCodeLink->setStyleSheet(blendedStyle); newFileLinkShortcut->setStyleSheet(blendedStyle); openFileShortcut->setStyleSheet(blendedStyle); clearRecentFilesLink->setStyleSheet(blendedStyle); poweredByKDELink->setStyleSheet(blendedStyle); recentDocumentsListView->setStyleSheet(blendedStyle); newFileLink->setStyleSheet(blendedStyle); openFileLink->setStyleSheet(blendedStyle); // giving the drag area messaging a dotted border QString dottedBorderStyle = QString("border: 2px dotted ").append(blendedColor.name()).append("; color:").append(blendedColor.name()).append( ";"); dragImageHereLabel->setStyleSheet(dottedBorderStyle); // make drop area QFrame have a dotted line dropFrameBorder->setObjectName("dropAreaIndicator"); QString dropFrameStyle = QString("QFrame#dropAreaIndicator { border: 4px dotted ").append(blendedColor.name()).append("}"); dropFrameBorder->setStyleSheet(dropFrameStyle); // only show drop area when we have a document over the empty area showDropAreaIndicator(false); // add icons for new and open settings to make them stand out a bit more openFileLink->setIconSize(QSize(30, 30)); newFileLink->setIconSize(QSize(30, 30)); openFileLink->setIcon(KisIconUtils::loadIcon("document-open")); newFileLink->setIcon(KisIconUtils::loadIcon("document-new")); // needed for updating icon color for files that don't have a preview if (mainWindow) { populateRecentDocuments(); } } void KisWelcomePageWidget::populateRecentDocuments() { // grab recent files data recentFilesModel = new QStandardItemModel(); int recentDocumentsIterator = mainWindow->recentFilesUrls().length() > 5 ? 5 : mainWindow->recentFilesUrls().length(); // grab at most 5 for (int i = 0; i < recentDocumentsIterator; i++ ) { QStandardItem *recentItem = new QStandardItem(1,2); // 1 row, 1 column QString recentFileUrlPath = mainWindow->recentFilesUrls().at(i).toString(); QString fileName = recentFileUrlPath.split("/").last(); // get thumbnail -- almost all Krita-supported formats save a thumbnail // this was mostly copied from the KisAutoSaveRecovery file QScopedPointer store(KoStore::createStore(QUrl(recentFileUrlPath), KoStore::Read)); if (store) { if (store->open(QString("Thumbnails/thumbnail.png")) || store->open(QString("preview.png"))) { QByteArray bytes = store->read(store->size()); store->close(); QImage img; img.loadFromData(bytes); recentItem->setIcon(QIcon(QPixmap::fromImage(img))); } else { recentItem->setIcon(KisIconUtils::loadIcon("document-export")); } } else { recentItem->setIcon(KisIconUtils::loadIcon("document-export")); } // set the recent object with the data recentItem->setText(fileName); // what to display for the item recentItem->setToolTip(recentFileUrlPath); recentFilesModel->appendRow(recentItem); } // hide clear and Recent files title if there are none bool hasRecentFiles = mainWindow->recentFilesUrls().length() > 0; recentDocumentsLabel->setVisible(hasRecentFiles); clearRecentFilesLink->setVisible(hasRecentFiles); recentDocumentsListView->setIconSize(QSize(40, 40)); recentDocumentsListView->setModel(recentFilesModel); } void KisWelcomePageWidget::recentDocumentClicked(QModelIndex index) { QString fileUrl = index.data(Qt::ToolTipRole).toString(); mainWindow->openDocument(QUrl(fileUrl), KisMainWindow::None ); } void KisWelcomePageWidget::slotNewFileClicked() { mainWindow->slotFileNew(); } void KisWelcomePageWidget::slotOpenFileClicked() { mainWindow->slotFileOpen(); } void KisWelcomePageWidget::slotClearRecentFiles() { mainWindow->clearRecentFiles(); mainWindow->reloadRecentFileList(); populateRecentDocuments(); } void KisWelcomePageWidget::slotGoToManual() { QDesktopServices::openUrl(QUrl("https://docs.krita.org")); } void KisWelcomePageWidget::slotGettingStarted() { QDesktopServices::openUrl(QUrl("https://docs.krita.org/en/user_manual/getting_started.html")); } void KisWelcomePageWidget::slotSupportKrita() { QDesktopServices::openUrl(QUrl("https://krita.org/en/support-us/donations/")); } void KisWelcomePageWidget::slotUserCommunity() { QDesktopServices::openUrl(QUrl("https://forum.kde.org/viewforum.php?f=136")); } void KisWelcomePageWidget::slotKritaWebsite() { QDesktopServices::openUrl(QUrl("https://www.krita.org")); } void KisWelcomePageWidget::slotSourceCode() { QDesktopServices::openUrl(QUrl("https://phabricator.kde.org/source/krita/")); } void KisWelcomePageWidget::slotKDESiteLink() { QDesktopServices::openUrl(QUrl("https://userbase.kde.org/What_is_KDE")); } diff --git a/libs/ui/forms/KisNewsPage.ui b/libs/ui/forms/KisNewsPage.ui index 7fdff32d5a..6299f98686 100644 --- a/libs/ui/forms/KisNewsPage.ui +++ b/libs/ui/forms/KisNewsPage.ui @@ -1,31 +1,27 @@ KisNewsPage 0 0 400 300 - - - - Show news about Krita: this needs internet to retrieve information from the krita.org website - - - Show News about Krita - - - + + 0 + + + 0 + diff --git a/libs/ui/forms/KisWelcomePage.ui b/libs/ui/forms/KisWelcomePage.ui index 0d2214d990..25a4a94bbb 100644 --- a/libs/ui/forms/KisWelcomePage.ui +++ b/libs/ui/forms/KisWelcomePage.ui @@ -1,775 +1,804 @@ KisWelcomePage 0 0 - 1061 - 538 + 703 + 469 0 0 false - + QFrame::Box QFrame::Plain 4 0 - - - - Qt::Vertical - - - - 5 - 5 - - - - - - - - Qt::Horizontal - - - - 5 - 5 - - - - - - + + 5 + + 0 + 0 - 20 + 30 + + + 0 - + 18 - Start + Community + + + 0 - + 0 - + + + + 0 + 0 + + true Qt::NoFocus - New File + User Manual false true - - + + + Qt::Horizontal + + + QSizePolicy::Expanding + + - 20 - 0 + 40 + 5 + + + + + + + + 0 + + + - false + true + + Qt::NoFocus + - + Getting Started + + + false + + + true - + Qt::Horizontal 40 - 20 + 5 - - - 0 - - - 30 - + - + true Qt::NoFocus - Open File + Support Krita false true - - + + + Qt::Horizontal + + - 20 - 0 + 40 + 20 + + + + + + + + - false + true + + Qt::NoFocus + - + User Community + + + false + + + true - + Qt::Horizontal 40 20 - + - + - 18 + true + + Qt::NoFocus + - Recent Documents + Krita Website + + + false + + + true - - - - 0 - 0 - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + + + 0 + + + true Qt::NoFocus - Clear + Source Code false true - + Qt::Horizontal - 5 + 40 20 - - - - 0 - 0 - - - - - 300 - 250 - - - - - true - false - - - - Qt::NoFocus - - - false - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - false - - - false - - - QAbstractItemView::SelectItems - - - QListView::Snap - - - QListView::Fixed - - - 0 - - - QListView::ListMode - - - true - - - false - - - - - - - - - 5 - - - 0 - - - 0 - - - 30 - - - 0 - - - - - - 18 - - - - Community - - - 0 - - - - - - - 0 + + + 20 - - - - 0 - 0 - - + true Qt::NoFocus - User Manual + Powered by KDE false true - + Qt::Horizontal - - QSizePolicy::Expanding - 40 - 5 + 20 - - - 0 - + - - - - true - + + + + 0 + 0 + - - Qt::NoFocus + + QFrame::Box + + + 2 - Getting Started + Drag Image in window to open - - false + + Qt::AlignCenter - + true + + 30 + - + Qt::Horizontal 40 - 5 + 20 - + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + Qt::Horizontal + + + + 5 + 5 + + + + + + + + Qt::Vertical + + + + 5 + 5 + + + + + + + + Qt::Vertical + + + + 5 + 5 + + + + + + + + Qt::Horizontal + + + + 5 + 5 + + + + + + + + 5 + + + 0 + + + 20 + + + + + + 18 + + + + Start + + + + + + + 0 + - + true Qt::NoFocus - Support Krita + New File false true - - - Qt::Horizontal - - + + - 40 - 20 + 20 + 0 - - - - - - - - - true + false - - Qt::NoFocus - - User Community - - - false - - - true + - + Qt::Horizontal 40 20 - + + + 0 + + + 30 + - + true Qt::NoFocus - Krita Website + Open File false true - - - Qt::Horizontal - - + + - 40 - 20 + 20 + 0 - - - - - - - - 0 - - - 0 - - - - true + false - - Qt::NoFocus - - Source Code - - - false - - - true + - + Qt::Horizontal 40 20 - - - 20 - + - + + + + 18 + + + + Recent Documents + + + + + + + + 0 + 0 + + true Qt::NoFocus - Powered by KDE + Clear false true - + Qt::Horizontal - 40 + 5 20 - + + + + 0 + 0 + + + + + 300 + 250 + + + + + true + false + + + + Qt::NoFocus + + + false + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + false + + + false + + + QAbstractItemView::SelectItems + + + QListView::Snap + + + QListView::Fixed + + + 0 + + + QListView::ListMode + + + true + + + false + + + + + + + + + - + - + 0 0 - - QFrame::Box - - - 2 + + + 18 + - Drag Image in window to open - - - Qt::AlignCenter - - - true + News - 30 + 0 - - - Qt::Horizontal + + + true - - - 40 - 20 - + + + 0 + 0 + - + + Show news about Krita: this needs internet to retrieve information from the krita.org website + + + Enabled + + - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - - - - - - 18 - - - - News - - - 0 - - - - - - - Qt::Horizontal - - - - 5 - 5 - - - - - - - - Qt::Vertical - - - - 5 - 5 - - - - KisNewsWidget QWidget
widgets/KisNewsWidget.h
1
diff --git a/libs/ui/widgets/KisNewsWidget.cpp b/libs/ui/widgets/KisNewsWidget.cpp index 15b7d73965..5a2cd2a5c0 100644 --- a/libs/ui/widgets/KisNewsWidget.cpp +++ b/libs/ui/widgets/KisNewsWidget.cpp @@ -1,121 +1,112 @@ /* * Copyright (c) 2018 boud * * 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. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisNewsWidget.h" #include #include #include #include #include #include #include #include "kis_config.h" #include "KisMultiFeedRSSModel.h" KisNewsDelegate::KisNewsDelegate(QObject *parent) : QStyledItemDelegate(parent) { qDebug() << "Delegate created"; } void KisNewsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); QStyleOptionViewItem optionCopy = option; initStyleOption(&optionCopy, index); QStyle *style = optionCopy.widget? optionCopy.widget->style() : QApplication::style(); QTextDocument doc; doc.setHtml(optionCopy.text); + doc.setDocumentMargin(10); /// Painting item without text optionCopy.text = QString(); style->drawControl(QStyle::CE_ItemViewItem, &optionCopy, painter); QAbstractTextDocumentLayout::PaintContext ctx; // Highlighting text if item is selected if (optionCopy.state & QStyle::State_Selected) { ctx.palette.setColor(QPalette::Text, optionCopy.palette.color(QPalette::Active, QPalette::HighlightedText)); } painter->translate(optionCopy.rect.left(), optionCopy.rect.top()); QRect clip(0, 0, optionCopy.rect.width(), optionCopy.rect.height()); doc.setPageSize(clip.size()); doc.drawContents(painter, clip); painter->restore(); } QSize KisNewsDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem optionCopy = option; initStyleOption(&optionCopy, index); QTextDocument doc; doc.setHtml(optionCopy.text); doc.setTextWidth(optionCopy.rect.width()); return QSize(doc.idealWidth(), doc.size().height()); } KisNewsWidget::KisNewsWidget(QWidget *parent) : QWidget(parent) { setupUi(this); - KisConfig cfg(true); - m_getNews = cfg.readEntry("FetchNews", false); - chkShowNews->setChecked(m_getNews); - connect(chkShowNews, SIGNAL(toggled(bool)), this, SLOT(toggleNews(bool))); m_rssModel = new MultiFeedRssModel(this); - if (m_getNews) { - m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); - } - else { - m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); - } + setCursor(Qt::PointingHandCursor); listNews->setModel(m_rssModel); listNews->setItemDelegate(new KisNewsDelegate(listNews)); connect(listNews, SIGNAL(clicked(const QModelIndex&)), this, SLOT(itemSelected(const QModelIndex&))); } void KisNewsWidget::toggleNews(bool toggle) { KisConfig cfg(false); cfg.writeEntry("FetchNews", toggle); - m_getNews = toggle; - if (m_getNews) { + if (toggle) { m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); } else { m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); } } void KisNewsWidget::itemSelected(const QModelIndex &idx) { if (idx.isValid()) { QString link = idx.data(RssRoles::LinkRole).toString(); QDesktopServices::openUrl(QUrl(link)); } } diff --git a/libs/ui/widgets/KisNewsWidget.h b/libs/ui/widgets/KisNewsWidget.h index acb3e66b3a..4dda2f4512 100644 --- a/libs/ui/widgets/KisNewsWidget.h +++ b/libs/ui/widgets/KisNewsWidget.h @@ -1,54 +1,57 @@ /* * Copyright (c) 2018 boud * * 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. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISNEWSWIDGET_H #define KISNEWSWIDGET_H #include #include #include #include class MultiFeedRssModel; class KisNewsDelegate : public QStyledItemDelegate { Q_OBJECT public: KisNewsDelegate(QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; /** * @brief The KisNewsWidget class shows the latest news from Krita.org */ class KisNewsWidget : public QWidget, public Ui::KisNewsPage { Q_OBJECT public: explicit KisNewsWidget(QWidget *parent = nullptr); + + + private Q_SLOTS: void toggleNews(bool toggle); void itemSelected(const QModelIndex &idx); private: bool m_getNews {false}; MultiFeedRssModel *m_rssModel {0}; }; #endif // KISNEWSWIDGET_H