mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
Better shortcut handling in views
- display shortcuts - shortcut for resize
This commit is contained in:
@@ -46,6 +46,12 @@ namespace BlackGui
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QKeySequence &CShortcut::keyResizeView()
|
||||||
|
{
|
||||||
|
static const QKeySequence k(Qt::CTRL + Qt::Key_R);
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
|
||||||
const QKeySequence &CShortcut::keySave()
|
const QKeySequence &CShortcut::keySave()
|
||||||
{
|
{
|
||||||
static const QKeySequence k(Qt::CTRL + Qt::Key_S);
|
static const QKeySequence k(Qt::CTRL + Qt::Key_S);
|
||||||
@@ -94,4 +100,10 @@ namespace BlackGui
|
|||||||
static const QKeySequence k(Qt::CTRL + Qt::Key_0);
|
static const QKeySequence k(Qt::CTRL + Qt::Key_0);
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString CShortcut::toParenthesisString(const QKeySequence &sequence)
|
||||||
|
{
|
||||||
|
static const QString s("(%1)");
|
||||||
|
return s.arg(sequence.toString());
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ namespace BlackGui
|
|||||||
//! Display filter
|
//! Display filter
|
||||||
static const QKeySequence &keyDisplayFilter();
|
static const QKeySequence &keyDisplayFilter();
|
||||||
|
|
||||||
|
//! Resize view
|
||||||
|
static const QKeySequence &keyResizeView();
|
||||||
|
|
||||||
//! Save depending on context
|
//! Save depending on context
|
||||||
static const QKeySequence &keySave();
|
static const QKeySequence &keySave();
|
||||||
|
|
||||||
@@ -67,6 +70,9 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Font reset
|
//! Font reset
|
||||||
static const QKeySequence &keyFontReset();
|
static const QKeySequence &keyFontReset();
|
||||||
|
|
||||||
|
//! As string for menus etc. Looks like "(CTRL + R)"
|
||||||
|
static const QString toParenthesisString(const QKeySequence &sequence);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -109,9 +109,14 @@ namespace BlackGui
|
|||||||
deleteRow->setContext(Qt::WidgetShortcut);
|
deleteRow->setContext(Qt::WidgetShortcut);
|
||||||
|
|
||||||
QShortcut *copy = new QShortcut(CShortcut::keyCopy(), this);
|
QShortcut *copy = new QShortcut(CShortcut::keyCopy(), this);
|
||||||
connect(copy, &QShortcut::activated, this, &CViewBaseNonTemplate::ps_copy);
|
connect(copy, &QShortcut::activated, this, &CViewBaseNonTemplate::copy);
|
||||||
copy->setObjectName("Copy selection shortcut for " + this->objectName());
|
copy->setObjectName("Copy selection shortcut for " + this->objectName());
|
||||||
copy->setContext(Qt::WidgetShortcut);
|
copy->setContext(Qt::WidgetShortcut);
|
||||||
|
|
||||||
|
QShortcut *resize = new QShortcut(CShortcut::keyResizeView(), this);
|
||||||
|
connect(resize, &QShortcut::activated, this, &CViewBaseNonTemplate::fullResizeToContents);
|
||||||
|
resize->setObjectName("Resize view shortcut for " + this->objectName());
|
||||||
|
resize->setContext(Qt::WidgetShortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
CViewBaseNonTemplate::~CViewBaseNonTemplate()
|
CViewBaseNonTemplate::~CViewBaseNonTemplate()
|
||||||
@@ -265,30 +270,30 @@ namespace BlackGui
|
|||||||
if (m_filterWidget)
|
if (m_filterWidget)
|
||||||
{
|
{
|
||||||
const bool dialog = qobject_cast<QDialog *>(m_filterWidget);
|
const bool dialog = qobject_cast<QDialog *>(m_filterWidget);
|
||||||
if (dialog) ma.addAction(CIcons::filter16(), "Show filter", CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::displayFilterDialog }, CShortcut::keyDisplayFilter());
|
if (dialog) ma.addAction(CIcons::filter16(), "Show filter " + CShortcut::toParenthesisString(CShortcut::keyDisplayFilter()), CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::displayFilterDialog }, CShortcut::keyDisplayFilter());
|
||||||
ma.addAction(CIcons::filter16(), "Remove Filter", CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::ps_removeFilter });
|
ma.addAction(CIcons::filter16(), "Remove Filter", CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::ps_removeFilter });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MenuMaterializeFilter: { ma.addAction(CIcons::tableRelationship16(), "Materialize filtered data", CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::materializeFilter }); break; }
|
case MenuMaterializeFilter: { ma.addAction(CIcons::tableRelationship16(), "Materialize filtered data", CMenuAction::pathViewFilter(), { this, &CViewBaseNonTemplate::materializeFilter }); break; }
|
||||||
case MenuLoad: { ma.addAction(CIcons::disk16(), "Load from file", CMenuAction::pathViewLoadSave(), { this, &CViewBaseNonTemplate::loadJsonAction }); break; }
|
case MenuLoad: { ma.addAction(CIcons::disk16(), "Load from file ", CMenuAction::pathViewLoadSave(), { this, &CViewBaseNonTemplate::loadJsonAction }); break; }
|
||||||
case MenuSave: { ma.addAction(CIcons::disk16(), "Save data in file", CMenuAction::pathViewLoadSave(), { this, &CViewBaseNonTemplate::saveJsonAction }, CShortcut::keySaveViews()); break; }
|
case MenuSave: { ma.addAction(CIcons::disk16(), "Save data in file " + CShortcut::toParenthesisString(CShortcut::keySaveViews()), CMenuAction::pathViewLoadSave(), { this, &CViewBaseNonTemplate::saveJsonAction }, CShortcut::keySaveViews()); break; }
|
||||||
case MenuCut:
|
case MenuCut:
|
||||||
{
|
{
|
||||||
if (!QApplication::clipboard()) break;
|
if (!QApplication::clipboard()) break;
|
||||||
ma.addAction(CIcons::cut16(), "Cut", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::ps_cut }, QKeySequence(QKeySequence::Paste));
|
ma.addAction(CIcons::cut16(), "Cut", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::cut }, QKeySequence(QKeySequence::Paste));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MenuPaste:
|
case MenuPaste:
|
||||||
{
|
{
|
||||||
if (!QApplication::clipboard()) break;
|
if (!QApplication::clipboard()) break;
|
||||||
ma.addAction(CIcons::paste16(), "Paste", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::ps_paste }, QKeySequence(QKeySequence::Paste));
|
ma.addAction(CIcons::paste16(), "Paste", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::paste }, QKeySequence(QKeySequence::Paste));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MenuCopy:
|
case MenuCopy:
|
||||||
{
|
{
|
||||||
if (!QApplication::clipboard()) break;
|
if (!QApplication::clipboard()) break;
|
||||||
ma.addAction(CIcons::copy16(), "Copy", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::ps_copy }, QKeySequence(QKeySequence::Copy));
|
ma.addAction(CIcons::copy16(), "Copy", CMenuAction::pathViewCutPaste(), { this, &CViewBaseNonTemplate::copy }, QKeySequence(QKeySequence::Copy));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -386,7 +391,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
if (sm != NoSelection)
|
if (sm != NoSelection)
|
||||||
{
|
{
|
||||||
menuActions.addAction("Clear selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::clearSelection }, CShortcut::keyClearSelection());
|
menuActions.addAction("Clear selection " + CShortcut::toParenthesisString(CShortcut::keyClearSelection()), CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::clearSelection }, CShortcut::keyClearSelection());
|
||||||
}
|
}
|
||||||
if ((m_originalSelectionMode == MultiSelection || m_originalSelectionMode == ExtendedSelection) && m_menus.testFlag(MenuToggleSelectionMode))
|
if ((m_originalSelectionMode == MultiSelection || m_originalSelectionMode == ExtendedSelection) && m_menus.testFlag(MenuToggleSelectionMode))
|
||||||
{
|
{
|
||||||
@@ -411,7 +416,7 @@ namespace BlackGui
|
|||||||
if (m_menus.testFlag(MenuSave) && !isEmpty()) { menuActions.addActions(this->initMenuActions(MenuSave)); }
|
if (m_menus.testFlag(MenuSave) && !isEmpty()) { menuActions.addActions(this->initMenuActions(MenuSave)); }
|
||||||
|
|
||||||
// resizing
|
// resizing
|
||||||
menuActions.addAction(CIcons::resize16(), "Resize", CMenuAction::pathViewResize(), nullptr, { this, &CViewBaseNonTemplate::presizeOrFullResizeToContents });
|
menuActions.addAction(CIcons::resize16(), "&Resize " + CShortcut::toParenthesisString(CShortcut::keyResizeView()), CMenuAction::pathViewResize(), nullptr, { this, &CViewBaseNonTemplate::presizeOrFullResizeToContents });
|
||||||
|
|
||||||
// resize to content might decrease performance,
|
// resize to content might decrease performance,
|
||||||
// so I only allow changing to "content resizing" if size matches
|
// so I only allow changing to "content resizing" if size matches
|
||||||
@@ -548,7 +553,7 @@ namespace BlackGui
|
|||||||
const QPointer<CViewBaseNonTemplate> guard(this);
|
const QPointer<CViewBaseNonTemplate> guard(this);
|
||||||
QTimer::singleShot(500, this, [ = ]()
|
QTimer::singleShot(500, this, [ = ]()
|
||||||
{
|
{
|
||||||
if (guard.isNull()) { return; }
|
if (!guard) { return; }
|
||||||
CViewBaseNonTemplate::settingsChanged();
|
CViewBaseNonTemplate::settingsChanged();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1609,7 +1614,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class ModelClass, class ContainerType, class ObjectType>
|
template<class ModelClass, class ContainerType, class ObjectType>
|
||||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_copy()
|
void CViewBase<ModelClass, ContainerType, ObjectType>::copy()
|
||||||
{
|
{
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
if (!clipboard) { return; }
|
if (!clipboard) { return; }
|
||||||
@@ -1622,15 +1627,15 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class ModelClass, class ContainerType, class ObjectType>
|
template<class ModelClass, class ContainerType, class ObjectType>
|
||||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_cut()
|
void CViewBase<ModelClass, ContainerType, ObjectType>::cut()
|
||||||
{
|
{
|
||||||
if (!QApplication::clipboard()) { return; }
|
if (!QApplication::clipboard()) { return; }
|
||||||
this->ps_copy();
|
this->copy();
|
||||||
this->removeSelectedRows();
|
this->removeSelectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ModelClass, class ContainerType, class ObjectType>
|
template<class ModelClass, class ContainerType, class ObjectType>
|
||||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_paste()
|
void CViewBase<ModelClass, ContainerType, ObjectType>::paste()
|
||||||
{
|
{
|
||||||
const QClipboard *clipboard = QApplication::clipboard();
|
const QClipboard *clipboard = QApplication::clipboard();
|
||||||
if (!clipboard) { return; }
|
if (!clipboard) { return; }
|
||||||
|
|||||||
@@ -467,6 +467,12 @@ namespace BlackGui
|
|||||||
//! \remark Default implementation, can be overridden with specifi implementation
|
//! \remark Default implementation, can be overridden with specifi implementation
|
||||||
virtual QString getRememberedLastJsonDirectory() const;
|
virtual QString getRememberedLastJsonDirectory() const;
|
||||||
|
|
||||||
|
//! Clipboard cut/copy/paste @{
|
||||||
|
virtual void copy() = 0;
|
||||||
|
virtual void cut() = 0;
|
||||||
|
virtual void paste() = 0;
|
||||||
|
//! @}
|
||||||
|
|
||||||
ResizeMode m_resizeMode = PresizeSubset; //!< mode
|
ResizeMode m_resizeMode = PresizeSubset; //!< mode
|
||||||
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
||||||
SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set
|
SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set
|
||||||
@@ -527,15 +533,6 @@ namespace BlackGui
|
|||||||
//! Trigger reload from backend by signal requestNewBackendData()
|
//! Trigger reload from backend by signal requestNewBackendData()
|
||||||
void ps_triggerReloadFromBackend();
|
void ps_triggerReloadFromBackend();
|
||||||
|
|
||||||
//! Copy
|
|
||||||
virtual void ps_copy() = 0;
|
|
||||||
|
|
||||||
//! Cut
|
|
||||||
virtual void ps_cut() = 0;
|
|
||||||
|
|
||||||
//! Paste
|
|
||||||
virtual void ps_paste() = 0;
|
|
||||||
|
|
||||||
// ------------ slots of CViewDbObjects ----------------
|
// ------------ slots of CViewDbObjects ----------------
|
||||||
// need to be declared here and overridden, as this is the only part with valid Q_OBJECT
|
// need to be declared here and overridden, as this is the only part with valid Q_OBJECT
|
||||||
|
|
||||||
@@ -725,6 +722,9 @@ namespace BlackGui
|
|||||||
virtual void updateSortIndicator() override;
|
virtual void updateSortIndicator() override;
|
||||||
virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver) override;
|
virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver) override;
|
||||||
virtual void drawDropIndicator(bool indicator) override;
|
virtual void drawDropIndicator(bool indicator) override;
|
||||||
|
virtual void copy() override;
|
||||||
|
virtual void cut() override;
|
||||||
|
virtual void paste() override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Modify JSON data loaded in BlackGui::Views::CViewBaseNonTemplate::ps_loadJson
|
//! Modify JSON data loaded in BlackGui::Views::CViewBaseNonTemplate::ps_loadJson
|
||||||
@@ -755,9 +755,6 @@ namespace BlackGui
|
|||||||
virtual void ps_rowSelected(const QModelIndex &index) override;
|
virtual void ps_rowSelected(const QModelIndex &index) override;
|
||||||
virtual BlackMisc::CStatusMessage ps_loadJson() override;
|
virtual BlackMisc::CStatusMessage ps_loadJson() override;
|
||||||
virtual BlackMisc::CStatusMessage ps_saveJson() override;
|
virtual BlackMisc::CStatusMessage ps_saveJson() override;
|
||||||
virtual void ps_copy() override;
|
|
||||||
virtual void ps_cut() override;
|
|
||||||
virtual void ps_paste() override;
|
|
||||||
//! @}
|
//! @}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user