File 2002-better-welcomeview.patch of Package kate
diff --git a/apps/lib/kateviewmanager.cpp b/apps/lib/kateviewmanager.cpp
index 9f7f0b0a2ceb14138d8b24dcbf7d0f870a8a4294..ba0c1e174d7d93925871e437a11bd32c732236ac 100644
--- a/apps/lib/kateviewmanager.cpp
+++ b/apps/lib/kateviewmanager.cpp
@@ -1836,6 +1836,7 @@ void KateViewManager::showWelcomeView()
auto welcomeView = new WelcomeView(this);
mainWindow()->addWidget(welcomeView);
+ welcomeView->findChild<QPushButton *>()->setFocus();
m_welcomeViewAlreadyShown = true;
}
@@ -1854,7 +1855,11 @@ void KateViewManager::triggerActiveViewFocus()
return;
}
if (auto v = activeViewSpace()->currentWidget()) {
- v->setFocus();
+ if (qobject_cast<WelcomeView *>(v)) {
+ v->findChild<QPushButton *>()->setFocus();
+ } else {
+ v->setFocus();
+ }
return;
}
});
diff --git a/apps/lib/welcomeview/recentitemsmodel.cpp b/apps/lib/welcomeview/recentitemsmodel.cpp
index 695089e8d93c1d58f98c378a515a3facf48351e3..f4a56f038d924c5593fa9b129ecc461215e95727 100644
--- a/apps/lib/welcomeview/recentitemsmodel.cpp
+++ b/apps/lib/welcomeview/recentitemsmodel.cpp
@@ -9,6 +9,7 @@
#include "ktexteditor_utils.h"
+#include <QFileInfo>
#include <QMimeDatabase>
RecentItemsModel::RecentItemsModel(QObject *parent)
@@ -53,10 +54,8 @@ void RecentItemsModel::refresh(const QList<QUrl> &urls)
QIcon icon;
QString name;
for (const QUrl &url : urls) {
- // lookup mime type without accessing file to avoid stall for e.g. NFS/SMB
- const QMimeType mimeType = QMimeDatabase().mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension);
- if (url.isLocalFile() || !mimeType.isDefault()) {
- icon = QIcon::fromTheme(mimeType.iconName());
+ if (url.isLocalFile()) {
+ icon = QIcon::fromTheme(QMimeDatabase().mimeTypeForFile(QFileInfo(url.toLocalFile())).iconName());
} else {
icon = QIcon::fromTheme(QStringLiteral("network-server"));
}
diff --git a/apps/lib/welcomeview/welcomeview.cpp b/apps/lib/welcomeview/welcomeview.cpp
index aceb8ef1282dd5b836f310c9e9c5ccf4c738bd6f..ba645ac78973a6a2d603873645fca44f5472f270 100644
--- a/apps/lib/welcomeview/welcomeview.cpp
+++ b/apps/lib/welcomeview/welcomeview.cpp
@@ -51,12 +51,6 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
setupUi(this);
listViewRecentItems->setSelectionMode(QAbstractItemView::MultiSelection);
-
- const KAboutData aboutData = KAboutData::applicationData();
- labelTitle->setText(i18n("Welcome to %1", aboutData.displayName()));
- labelDescription->setText(aboutData.shortDescription());
- labelIcon->setPixmap(aboutData.programLogo().value<QIcon>().pixmap(KIconLoader::SizeEnormous));
-
labelRecentItems->setText(KateApp::isKate() ? i18n("Recent Documents and Projects") : i18n("Recent Documents"));
m_placeholderRecentItems = new Placeholder;
@@ -93,8 +87,8 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
connect(buttonClearRecentItems, &QPushButton::clicked,
recentFilesAction, &KRecentFilesAction::clear);
- connect(labelHomepage, qOverload<>(&KUrlLabel::leftClickedUrl), this, [aboutData]() {
- QDesktopServices::openUrl(QUrl(aboutData.homepage()));
+ connect(labelHomepage, qOverload<>(&KUrlLabel::leftClickedUrl), this, []() {
+ QDesktopServices::openUrl(QUrl(KAboutData::applicationData().homepage()));
});
connect(labelContribute, qOverload<>(&KUrlLabel::leftClickedUrl), this, []() {
QDesktopServices::openUrl(QUrl(QStringLiteral("https://kate-editor.org/join-us")));
@@ -163,7 +157,7 @@ bool WelcomeView::event(QEvent *event)
updateButtons();
break;
case QEvent::Resize:
- if (updateLayout()) {
+ if (updateLayout() && isVisible()) {
return true;
}
break;
@@ -174,13 +168,6 @@ bool WelcomeView::event(QEvent *event)
return QScrollArea::event(event);
}
-void WelcomeView::resizeEvent(QResizeEvent *event)
-{
- QScrollArea::resizeEvent(event);
-
- updateLayout();
-}
-
bool WelcomeView::eventFilter(QObject *watched, QEvent *event)
{
KRecentFilesAction *recentFilesAction = m_viewManager->mainWindow()->recentFilesAction();
@@ -210,53 +197,53 @@ void WelcomeView::onRecentItemsContextMenuRequested(const QPoint &pos)
return;
}
- const QUrl url = m_recentItemsModel->url(index);
- Q_ASSERT(url.isValid());
+ QModelIndexList indexes;
+ if (listViewRecentItems->selectionModel()->isSelected(index)) {
+ indexes = listViewRecentItems->selectionModel()->selectedIndexes();
+ } else {
+ indexes << index;
+ }
QMenu contextMenu(listViewRecentItems);
- const auto selectedIndexes = listViewRecentItems->selectionModel()->selectedIndexes();
- auto allSelectedAreFiles = [this, selectedIndexes] {
- return std::all_of(selectedIndexes.begin(), selectedIndexes.end(), [model = m_recentItemsModel](const QModelIndex &index) {
- const QUrl url = model->url(index);
- return !url.isLocalFile() || QFileInfo(url.toLocalFile()).isFile();
- });
- };
- if (selectedIndexes.size() > 1 && allSelectedAreFiles()) {
- QAction *action = new QAction(i18n("Open Selected Files..."), this);
- action->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
- connect(action, &QAction::triggered, this, [this, selectedIndexes]() {
- for (const auto &index : selectedIndexes) {
- const auto url = m_recentItemsModel->url(index);
- if (url.isValid()) {
- m_viewManager->openUrl(url);
- }
+ QAction *action = new QAction(i18n("&Open"), this);
+ action->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
+ connect(action, &QAction::triggered, this, [this, indexes]() {
+ for (const QModelIndex &index : std::as_const(indexes)) {
+ const QUrl url = m_recentItemsModel->url(index);
+ if (url.isValid() && (!url.isLocalFile() || QFileInfo(url.toLocalFile()).isFile())) { // TODO : Open folders in new window
+ m_viewManager->openUrl(url);
}
- });
- contextMenu.addAction(action);
- }
-
- QAction *action = new QAction(i18n("Copy &Location"), this);
- action->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy-path")));
- connect(action, &QAction::triggered, this, [url]() {
- qApp->clipboard()->setText(url.toString(QUrl::PreferLocalFile));
+ }
});
contextMenu.addAction(action);
- action = new QAction(i18n("&Open Containing Folder"), this);
- action->setEnabled(url.isLocalFile());
- action->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
- connect(action, &QAction::triggered, this, [url]() {
- KIO::highlightInFileManager({url});
- });
- contextMenu.addAction(action);
+ if (indexes.size() == 1) {
+ const QUrl url = m_recentItemsModel->url(indexes.at(0));
+
+ action = new QAction(i18n("Copy &Location"), this);
+ action->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy-path")));
+ connect(action, &QAction::triggered, this, [url]() {
+ qApp->clipboard()->setText(url.toString(QUrl::PreferLocalFile));
+ });
+ contextMenu.addAction(action);
+
+ if (url.isLocalFile()) {
+ action = new QAction(i18n("Open Containing &Folder"), this);
+ action->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
+ connect(action, &QAction::triggered, this, [url]() {
+ KIO::highlightInFileManager({url});
+ });
+ contextMenu.addAction(action);
+ }
+ }
action = new QAction(i18n("&Remove"), this);
action->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
- connect(action, &QAction::triggered, this, [this, selectedIndexes]() {
+ connect(action, &QAction::triggered, this, [this, indexes]() {
KRecentFilesAction *recentFilesAction = m_viewManager->mainWindow()->recentFilesAction();
- for (const auto &index : selectedIndexes) {
- const auto url = m_recentItemsModel->url(index);
+ for (const QModelIndex &index : std::as_const(indexes)) {
+ const QUrl url = m_recentItemsModel->url(index);
if (url.isValid()) {
recentFilesAction->removeUrl(url);
}
@@ -284,11 +271,6 @@ void WelcomeView::updateButtons()
void WelcomeView::updateFonts()
{
- QFont titleFont = font();
- titleFont.setPointSize(titleFont.pointSize() + 6);
- titleFont.setWeight(QFont::Bold);
- labelTitle->setFont(titleFont);
-
QFont panelTitleFont = font();
panelTitleFont.setPointSize(panelTitleFont.pointSize() + 2);
labelRecentItems->setFont(panelTitleFont);
@@ -305,40 +287,25 @@ void WelcomeView::updateFonts()
bool WelcomeView::updateLayout()
{
- // Align labelHelp with labelRecentItems
+ // align labelHelp with labelRecentItems
labelHelp->setMinimumHeight(labelRecentItems->height());
- bool result = false;
-
- // show/hide widgetHeader depending on the view height
- if (widgetHeader->isVisible()) {
- if (height() <= frameContent->height()) {
- widgetHeader->hide();
- result = true;
- }
- } else {
- const int implicitHeight = frameContent->height() + widgetHeader->height() + layoutContent->spacing();
- if (height() > implicitHeight) {
- widgetHeader->show();
- result = true;
- }
- }
-
- // show/hide widgetHelp depending on the view height
+ // show/hide widgetHelp depending on the view width
+ int implicitWidth = layoutRoot->minimumSize().width();
if (widgetHelp->isVisible()) {
- if (width() <= frameContent->width()) {
+ if (width() <= implicitWidth) {
widgetHelp->hide();
- result = true;
+ return true;
}
} else {
- const int implicitWidth = frameContent->width() + widgetHelp->width() + layoutPanels->horizontalSpacing();
+ implicitWidth += widgetHelp->width() + layoutPanels->spacing();
if (width() > implicitWidth) {
widgetHelp->show();
return true;
}
}
- return result;
+ return false;
}
#include "moc_welcomeview.cpp"
diff --git a/apps/lib/welcomeview/welcomeview.h b/apps/lib/welcomeview/welcomeview.h
index 267260b6eae0f5b84d381ec3a95277b3ed7b8f58..f2b4547bb1ad196a50daad8291f04e224ba407d0 100644
--- a/apps/lib/welcomeview/welcomeview.h
+++ b/apps/lib/welcomeview/welcomeview.h
@@ -23,8 +23,6 @@ public:
protected:
bool event(QEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
-
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS:
diff --git a/apps/lib/welcomeview/welcomeview.ui b/apps/lib/welcomeview/welcomeview.ui
index 178a0a5f7b786c128867e42373116b520275880b..15579fed167b8ec92f80c4d64eccd81bd9f76048 100644
--- a/apps/lib/welcomeview/welcomeview.ui
+++ b/apps/lib/welcomeview/welcomeview.ui
@@ -31,22 +31,7 @@
<height>803</height>
</rect>
</property>
- <layout class="QGridLayout" name="layoutRoot" rowstretch="3,5,3" columnstretch="3,5,3">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>0</number>
- </property>
+ <layout class="QGridLayout" name="layoutRoot" rowstretch="1,6,1" columnstretch="1,3,1">
<item row="0" column="1">
<spacer name="spacer6">
<property name="orientation">
@@ -75,81 +60,22 @@
</item>
<item row="1" column="1">
<widget class="QFrame" name="frameContent">
- <layout class="QVBoxLayout" name="layoutContent" stretch="0,1,0">
+ <layout class="QVBoxLayout" name="layoutContent" stretch="1,0">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
<property name="spacing">
<number>20</number>
</property>
- <item>
- <widget class="QWidget" name="widgetHeader" native="true">
- <layout class="QHBoxLayout" name="layoutHeader" stretch="1,0,0,1">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item>
- <spacer name="spacer1">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </spacer>
- </item>
- <item alignment="Qt::AlignVCenter">
- <widget class="QLabel" name="labelIcon"/>
- </item>
- <item alignment="Qt::AlignVCenter">
- <widget class="QWidget" name="widgetAbout" native="true">
- <layout class="QVBoxLayout" name="verticalAbout">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item>
- <widget class="QLabel" name="labelTitle"/>
- </item>
- <item>
- <widget class="QLabel" name="labelDescription"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <spacer name="spacer2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </item>
<item>
<layout class="QGridLayout" name="layoutPanels" columnstretch="1,0">
<property name="spacing">
@@ -221,6 +147,12 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="textElideMode">
+ <enum>Qt::ElideMiddle</enum>
+ </property>
</widget>
</item>
<item row="4" column="0">
@@ -381,6 +313,12 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="textElideMode">
+ <enum>Qt::ElideMiddle</enum>
+ </property>
</widget>
</item>
<item row="2" column="0">