viewsdialog:show/hide views context menu actions

--based on a view is selected or not the relevant
actions are shown in the context menu
work/spdx
Michail Vourlakos 4 years ago
parent 05b2a59f25
commit e0ed86bd41

@ -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

@ -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
)

@ -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()) {

@ -31,6 +31,7 @@
// Qt
#include <QAbstractItemModel>
#include <QHash>
#include <QItemSelection>
#include <QSortFilterProxyModel>
#include <QTableView>
@ -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};

@ -87,7 +87,10 @@
<number>6</number>
</property>
<item row="1" column="0">
<widget class="QTableView" name="viewsTable">
<widget class="Latte::Settings::View::ViewsTableView" name="viewsTable">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@ -127,7 +130,8 @@
<string>Duplicate</string>
</property>
<property name="icon">
<iconset theme="edit-copy"/>
<iconset theme="edit-copy">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -222,6 +226,11 @@
<extends>QComboBox</extends>
<header>settings/generic/layoutscombobox.h</header>
</customwidget>
<customwidget>
<class>Latte::Settings::View::ViewsTableView</class>
<extends>QTableView</extends>
<header>settings/viewsdialog/viewstableview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>

@ -0,0 +1,56 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "viewstableview.h"
//! Qt
#include <QDebug>
#include <QModelIndex>
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();
}
}
}
}

@ -0,0 +1,50 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef VIEWSTABLEVIEW_H
#define VIEWSTABLEVIEW_H
// Qt
#include <QTableView>
#include <QMouseEvent>
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
Loading…
Cancel
Save