provide moveView through context menu

--the user can now user the ContextMenu in order
to move a view between different active layouts
work/spdx
Michail Vourlakos 4 years ago
parent 7f64126d5f
commit 631f4a9d6e

@ -21,6 +21,10 @@
<method name="duplicateView">
<arg name="containmentId" type="u" direction="in"/>
</method>
<method name="moveViewToLayout">
<arg name="containmentId" type="u" direction="in"/>
<arg name="layoutName" type="s" direction="in"/>
</method>
<method name="removeView">
<arg name="containmentId" type="u" direction="in"/>
</method>

@ -1179,6 +1179,14 @@ void Corona::exportViewTemplate(const uint &containmentId)
}
}
void Corona::moveViewToLayout(const uint &containmentId, const QString &layoutName)
{
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);
if (view && !layoutName.isEmpty() && view->layout()->name() != layoutName) {
view->positioner()->hideDockDuringMovingToLayout(layoutName);
}
}
void Corona::removeView(const uint &containmentId)
{
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);

@ -168,6 +168,7 @@ public slots:
void duplicateView(const uint &containmentId);
void exportViewTemplate(const uint &containmentId);
void moveViewToLayout(const uint &containmentId, const QString &layoutName);
void removeView(const uint &containmentId);
void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename);

@ -51,6 +51,7 @@ const char DUPLICATEVIEWNAME[] = "duplicate view";
const char EDITVIEWNAME[] = "edit view";
const char EXPORTVIEWTEMPLATENAME[] = "export view";
const char REMOVEVIEWNAME[] = "remove view";
const char MOVEVIEWNAME[] = "move view";
enum ViewType
{
@ -81,14 +82,18 @@ Menu::~Menu()
m_sectionAction->deleteLater();
m_separator->deleteLater();
//! sub-menus
m_switchLayoutsMenu->deleteLater();
//! actions
m_addWidgetsAction->deleteLater();
m_configureAction->deleteLater();
m_printAction->deleteLater();
m_switchLayoutsMenu->deleteLater();
m_layoutsAction->deleteLater();
m_moveAction->deleteLater();
m_preferenceAction->deleteLater();
m_removeAction->deleteLater();
m_quitApplication->deleteLater();
m_quitApplication->deleteLater();
}
void Menu::makeActions()
@ -142,6 +147,18 @@ void Menu::makeActions()
connect(m_switchLayoutsMenu, &QMenu::aboutToShow, this, &Menu::populateLayouts);
connect(m_switchLayoutsMenu, &QMenu::triggered, this, &Menu::switchToLayout);
//! Move submenu
m_moveToLayoutMenu = new QMenu;
m_moveAction = m_moveToLayoutMenu->menuAction();
m_moveAction->setVisible(containment()->isUserConfiguring());
m_moveAction->setText("Move To Layout");
m_moveAction->setIcon(QIcon::fromTheme("transform-move-horizontal"));
m_moveAction->setStatusTip(i18n("Move dock or panel to different layout"));
this->containment()->actions()->addAction(MOVEVIEWNAME, m_moveAction);
connect(m_moveToLayoutMenu, &QMenu::aboutToShow, this, &Menu::populateMoveToLayouts);
connect(m_moveToLayoutMenu, &QMenu::triggered, this, &Menu::moveToLayout);
//! Configure Latte
m_preferenceAction = new QAction(QIcon::fromTheme("configure"), i18nc("global settings window", "&Configure Latte..."), this);
this->containment()->actions()->addAction(PREFERENCESNAME, m_preferenceAction);
@ -221,6 +238,7 @@ QList<QAction *> Menu::contextualActions()
actions << m_addWidgetsAction;
actions << m_duplicateAction;
actions << m_exportViewAction;
actions << m_moveAction;
actions << m_configureAction;
actions << m_removeAction;
@ -244,6 +262,15 @@ QList<QAction *> Menu::contextualActions()
const QString exportTemplateText = (viewType == DockView) ? i18n("E&xport Dock as Template") : i18n("E&xport Panel as Template");
m_exportViewAction->setText(exportTemplateText);
QStringList activeNames = m_data[ACTIVELAYOUTSINDEX].split(";;");
if (activeNames.count() > 1 && containment()->isUserConfiguring()) {
m_moveAction->setVisible(true);
const QString moveText = (viewType == DockView) ? i18n("&Move Dock To Layout") : i18n("&Move Panel To Layout");
m_moveAction->setText(moveText);
} else {
m_moveAction->setVisible(false);
}
const QString removeActionText = (viewType == DockView) ? i18n("&Remove Dock") : i18n("&Remove Panel");
m_removeAction->setText(removeActionText);
@ -262,6 +289,8 @@ QAction *Menu::action(const QString &name)
return m_exportViewAction;
} else if (name == LAYOUTSNAME) {
return m_layoutsAction;
} else if (name == MOVEVIEWNAME) {
return m_moveAction;
} else if (name == PREFERENCESNAME) {
return m_preferenceAction;
} else if (name == QUITLATTENAME) {
@ -282,12 +311,14 @@ void Menu::onUserConfiguringChanged(const bool &configuring)
m_configureAction->setVisible(!configuring);
m_duplicateAction->setVisible(configuring);
m_exportViewAction->setVisible(configuring);
m_moveAction->setVisible(configuring);
m_removeAction->setVisible(configuring);
// because sometimes they are disabled unexpectedly, we should reenable them
m_configureAction->setEnabled(true);
m_duplicateAction->setEnabled(true);
m_exportViewAction->setEnabled(true);
m_moveAction->setEnabled(true);
m_removeAction->setEnabled(true);
}
@ -351,6 +382,66 @@ void Menu::populateLayouts()
editLayoutsAction->setData(QStringLiteral(" _show_latte_settings_dialog_"));
}
void Menu::populateMoveToLayouts()
{
m_moveToLayoutMenu->clear();
LayoutsMemoryUsage memoryUsage = static_cast<LayoutsMemoryUsage>((m_data[MEMORYINDEX]).toInt());
if (memoryUsage == LayoutsMemoryUsage::MultipleLayouts) {
QStringList activeNames = m_data[ACTIVELAYOUTSINDEX].split(";;");
QStringList currentNames = m_data[CURRENTLAYOUTSINDEX].split(";;");
QString viewLayoutName = m_data[VIEWLAYOUTINDEX];
bool hasActiveNoCurrentLayout{false};
if (memoryUsage == LayoutsMemoryUsage::MultipleLayouts) {
for (int i = 0; i<activeNames.count(); ++i) {
if (!currentNames.contains(activeNames[i])) {
hasActiveNoCurrentLayout = true;
break;
}
}
}
for(int i=0; i<activeNames.count(); ++i) {
QString layoutText = activeNames[i];
bool isCurrent = currentNames.contains(activeNames[i]);
bool isViewCurrentLayout = activeNames[i] == viewLayoutName;
if (isCurrent && hasActiveNoCurrentLayout) {
layoutText += QString(" " + i18nc("current layout", "[Current]"));
}
QAction *layoutAction = m_moveToLayoutMenu->addAction(layoutText);
layoutAction->setCheckable(true);
layoutAction->setChecked(isViewCurrentLayout);
layoutAction->setData(isViewCurrentLayout ? QString() : activeNames[i]);
if (isCurrent) {
QFont font = layoutAction->font();
font.setBold(true);
layoutAction->setFont(font);
}
}
}
}
void Menu::moveToLayout(QAction *action)
{
const QString layoutName = action->data().toString();
QTimer::singleShot(400, [this, layoutName]() {
QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("moveViewToLayout", containment()->id(), layoutName);
}
});
}
void Menu::switchToLayout(QAction *action)
{
const QString layout = action->data().toString();

@ -44,11 +44,13 @@ private Q_SLOTS:
void makeActions();
void onUserConfiguringChanged(const bool &configuring);
void populateLayouts();
void populateMoveToLayouts();
void quitApplication();
void requestConfiguration();
void requestWidgetExplorer();
void switchToLayout(QAction *action);
void moveToLayout(QAction *action);
void switchToLayout(QAction *action);
private:
QStringList m_data;
@ -62,13 +64,15 @@ private:
QAction *m_configureAction{nullptr};
QAction *m_duplicateAction{nullptr};
QAction *m_exportViewAction{nullptr};
QAction *m_printAction{nullptr};
QAction *m_layoutsAction{nullptr};
QAction *m_moveAction{nullptr};
QAction *m_preferenceAction{nullptr};
QAction *m_printAction{nullptr};
QAction *m_removeAction{nullptr};
QAction *m_quitApplication{nullptr};
QMenu *m_switchLayoutsMenu{nullptr};
QMenu *m_moveToLayoutMenu{nullptr};
};
#endif

@ -551,9 +551,6 @@ Loader {
if (item && item.actionId === "new:") {
latteView.layout.newView(item.templateId);
} else if (item && item.actionId === "move:") {
var layouts = actionsComboBtn.centralLayoutsNames;
latteView.positioner.hideDockDuringMovingToLayout(layouts[index-1]);
}
actionsComboBtn.comboBox.currentIndex = -1;
@ -568,11 +565,6 @@ Loader {
}
}
Connections{
target: latteView
onLayoutChanged: actionsComboBtn.updateModel();
}
Connections{
target: viewConfig
onIsReadyChanged: {
@ -589,29 +581,6 @@ Loader {
function updateModel() {
actionsModel.clear();
var tempCentralLayouts = layoutsManager.centralLayoutsNames();
if (tempCentralLayouts.length > 0) {
var curIndex = tempCentralLayouts.indexOf(latteView.layout.name);
if (curIndex >=0) {
tempCentralLayouts.splice(curIndex,1);
}
centralLayoutsNames = tempCentralLayouts;
var iconArrow = Qt.application.layoutDirection === Qt.RightToLeft ? 'arrow-left' : 'arrow-right';
for(var i=0; i<centralLayoutsNames.length; ++i) {
var layout = {
actionId: 'move:',
enabled: true,
name: i18n("Move to %0").arg(centralLayoutsNames[i]),
icon: iconArrow
};
actionsModel.append(layout);
}
}
var viewTemplateIds = layoutsManager.viewTemplateIds();
var viewTemplateNames = layoutsManager.viewTemplateNames();

Loading…
Cancel
Save