diff --git a/app/settings/settingsdialog/layoutscontroller.cpp b/app/settings/settingsdialog/layoutscontroller.cpp index 1e4a7358f..42d2eb1a8 100644 --- a/app/settings/settingsdialog/layoutscontroller.cpp +++ b/app/settings/settingsdialog/layoutscontroller.cpp @@ -184,9 +184,7 @@ void Layouts::setOriginalInMultipleMode(const bool &inmultiple) bool Layouts::hasSelectedLayout() const { - int selectedRow = m_view->currentIndex().row(); - - return (selectedRow >= 0); + return m_view->selectionModel()->hasSelection(); } bool Layouts::isSelectedLayoutOriginal() const diff --git a/app/settings/viewsdialog/CMakeLists.txt b/app/settings/viewsdialog/CMakeLists.txt index f8445ecb6..e9f34683e 100644 --- a/app/settings/viewsdialog/CMakeLists.txt +++ b/app/settings/viewsdialog/CMakeLists.txt @@ -4,6 +4,7 @@ set(lattedock-app_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/viewsdialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/viewshandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/viewsmodel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/viewstableview.cpp PARENT_SCOPE ) diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp index bab4eb90f..9bde19447 100644 --- a/app/settings/viewsdialog/viewscontroller.cpp +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -25,6 +25,7 @@ #include "viewsdialog.h" #include "viewshandler.h" #include "viewsmodel.h" +#include "viewstableview.h" #include "delegates/namedelegate.h" #include "delegates/singleoptiondelegate.h" #include "delegates/singletextdelegate.h" @@ -107,8 +108,6 @@ void Views::init() applyColumnWidths(); - m_view->setContextMenuPolicy(Qt::ActionsContextMenu); - m_cutAction = new QAction(QIcon::fromTheme("edit-cut"), i18n("Cut"), m_view); m_cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); @@ -127,6 +126,7 @@ void Views::init() m_view->addAction(m_pasteAction); m_view->addAction(m_duplicateAction); + connect(m_view, &View::ViewsTableView::selectionsChanged, this, &Views::onSelectionsChanged); connect(m_view, &QObject::destroyed, this, &Views::storeColumnWidths); connect(m_view->horizontalHeader(), &QObject::destroyed, this, [&]() { @@ -147,9 +147,7 @@ bool Views::hasChangedData() const bool Views::hasSelectedView() const { - int selectedRow = m_view->currentIndex().row(); - - return (selectedRow >= 0); + return m_view->selectionModel()->hasSelection(); } int Views::rowForId(QString id) const @@ -244,6 +242,16 @@ void Views::onCurrentLayoutChanged() m_model->setOriginalData(layout.views); } +void Views::onSelectionsChanged() +{ + bool hasselectedview = hasSelectedView(); + + m_cutAction->setVisible(hasselectedview); + m_copyAction->setVisible(hasselectedview); + m_duplicateAction->setVisible(hasselectedview); + m_pasteAction->setVisible(!hasselectedview); +} + int Views::viewsForRemovalCount() const { if (!hasChangedData()) { diff --git a/app/settings/viewsdialog/viewscontroller.h b/app/settings/viewsdialog/viewscontroller.h index 3831a372d..113321829 100644 --- a/app/settings/viewsdialog/viewscontroller.h +++ b/app/settings/viewsdialog/viewscontroller.h @@ -31,6 +31,7 @@ // Qt #include #include +#include #include #include @@ -43,6 +44,9 @@ namespace Settings { namespace Handler { class ViewsHandler; } +namespace View { +class ViewsTableView; +} } } @@ -100,11 +104,12 @@ private slots: void applyColumnWidths(); void onCurrentLayoutChanged(); + void onSelectionsChanged(); private: Settings::Handler::ViewsHandler *m_handler{nullptr}; - QTableView *m_view{nullptr}; + Settings::View::ViewsTableView *m_view{nullptr}; //! layoutsView ui settings int m_viewSortColumn{Model::Views::SCREENCOLUMN}; diff --git a/app/settings/viewsdialog/viewsdialog.ui b/app/settings/viewsdialog/viewsdialog.ui index f3dfb8904..46c8df6ea 100644 --- a/app/settings/viewsdialog/viewsdialog.ui +++ b/app/settings/viewsdialog/viewsdialog.ui @@ -87,7 +87,10 @@ 6 - + + + Qt::ActionsContextMenu + true @@ -127,7 +130,8 @@ Duplicate - + + .. @@ -222,6 +226,11 @@ QComboBox
settings/generic/layoutscombobox.h
+ + Latte::Settings::View::ViewsTableView + QTableView +
settings/viewsdialog/viewstableview.h
+
diff --git a/app/settings/viewsdialog/viewstableview.cpp b/app/settings/viewsdialog/viewstableview.cpp new file mode 100644 index 000000000..35c5f2e70 --- /dev/null +++ b/app/settings/viewsdialog/viewstableview.cpp @@ -0,0 +1,56 @@ +/* +* Copyright 2020 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#include "viewstableview.h" + +//! Qt +#include +#include + + +namespace Latte { +namespace Settings { +namespace View { + +ViewsTableView::ViewsTableView(QWidget *parent) + : QTableView(parent) +{ +} + +void ViewsTableView::mousePressEvent(QMouseEvent *event) +{ + QModelIndex eventIndex = indexAt(event->pos()); + + if (!eventIndex.isValid()) { + clearSelection(); + } + + QTableView::mousePressEvent(event); +} + +void ViewsTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) +{ + QAbstractItemView::selectionChanged(selected, deselected); + emit selectionsChanged(); +} + +} +} +} + diff --git a/app/settings/viewsdialog/viewstableview.h b/app/settings/viewsdialog/viewstableview.h new file mode 100644 index 000000000..8c71609c0 --- /dev/null +++ b/app/settings/viewsdialog/viewstableview.h @@ -0,0 +1,50 @@ +/* +* Copyright 2021 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#ifndef VIEWSTABLEVIEW_H +#define VIEWSTABLEVIEW_H + +// Qt +#include +#include + +namespace Latte { +namespace Settings { +namespace View { + +class ViewsTableView : public QTableView +{ + Q_OBJECT +public: + ViewsTableView(QWidget *parent = nullptr); + +signals: + void selectionsChanged(); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; + + +}; + +} +} +} +#endif