mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
@@ -32,10 +32,10 @@ namespace BlackGui
|
||||
void addAcceptedMetaTypeId(int id);
|
||||
|
||||
//! Drop allowed
|
||||
bool isDropAllowed() const;
|
||||
virtual bool isDropAllowed() const;
|
||||
|
||||
//! Drop allowed
|
||||
void allowDrop(bool allowed);
|
||||
virtual void allowDrop(bool allowed);
|
||||
|
||||
//! Mime data to CVariant (normally encapsulating a value object)
|
||||
BlackMisc::CVariant toCVariant(const QMimeData *mime) const;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "blackgui/models/allmodels.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/shortcut.h"
|
||||
#include "blackcore/registermetadata.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
@@ -33,7 +34,8 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CViewBaseNonTemplate::CViewBaseNonTemplate(QWidget *parent) : QTableView(parent)
|
||||
CViewBaseNonTemplate::CViewBaseNonTemplate(QWidget *parent) :
|
||||
QTableView(parent)
|
||||
{
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::ps_customMenuRequested);
|
||||
@@ -45,10 +47,17 @@ namespace BlackGui
|
||||
this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
this->setWordWrap(true);
|
||||
|
||||
QShortcut *filter = new QShortcut(FilterKey, this);
|
||||
bool c = connect(filter, &QShortcut::activated, this, &CViewBaseNonTemplate::ps_displayFilterDialog);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
QShortcut *filter = new QShortcut(CShortcut::keyDisplayFilter(), this, SLOT(ps_displayFilterDialog()), nullptr, Qt::WidgetShortcut);
|
||||
filter->setObjectName("Filter shortcut for " + this->objectName());
|
||||
|
||||
QShortcut *clearSelection = new QShortcut(CShortcut::keyClearSelection(), this, SLOT(clearSelection()), nullptr, Qt::WidgetShortcut);
|
||||
clearSelection->setObjectName("Cleat selection shortcut for " + this->objectName());
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget)
|
||||
{
|
||||
bool c = CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget);
|
||||
return c;
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::resizeToContents()
|
||||
@@ -93,26 +102,6 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::setCustomMenu(IMenuDelegate *menu, bool nestPreviousMenu)
|
||||
{
|
||||
if (menu && nestPreviousMenu)
|
||||
{
|
||||
// new menu with nesting
|
||||
menu->setNestedDelegate(this->m_menu);
|
||||
m_menu = menu;
|
||||
}
|
||||
else if (!menu && nestPreviousMenu)
|
||||
{
|
||||
// nested new menu
|
||||
m_menu = m_menu->getNestedDelegate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// no nesting
|
||||
m_menu = menu;
|
||||
}
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::enableLoadIndicator(bool enable)
|
||||
{
|
||||
m_enabledLoadIndicator = enable;
|
||||
@@ -138,6 +127,26 @@ namespace BlackGui
|
||||
return CGuiUtility::mainApplicationWindowWidget();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::setCustomMenu(IMenuDelegate *menu, bool nestPreviousMenu)
|
||||
{
|
||||
if (menu && nestPreviousMenu)
|
||||
{
|
||||
// new menu with nesting
|
||||
menu->setNestedDelegate(this->m_menu);
|
||||
m_menu = menu;
|
||||
}
|
||||
else if (!menu && nestPreviousMenu)
|
||||
{
|
||||
// nested new menu
|
||||
m_menu = m_menu->getNestedDelegate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// no nesting
|
||||
m_menu = menu;
|
||||
}
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::customMenu(QMenu &menu) const
|
||||
{
|
||||
// delegate?
|
||||
@@ -158,11 +167,20 @@ namespace BlackGui
|
||||
|
||||
if (this->m_withMenuFilter)
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Filter", this, SLOT(ps_displayFilterDialog()), FilterKey);
|
||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Filter", this, SLOT(ps_displayFilterDialog()), CShortcut::keyDisplayFilter());
|
||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Remove Filter", this, SLOT(ps_removeFilter()));
|
||||
}
|
||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
||||
|
||||
// selection menus
|
||||
SelectionMode sm = this->selectionMode();
|
||||
if (sm == MultiSelection || sm == ExtendedSelection)
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::empty16(), "Select all", this, SLOT(selectAll()), Qt::CTRL + Qt::Key_A);
|
||||
}
|
||||
menu.addAction(BlackMisc::CIcons::empty16(), "Clear selection", this, SLOT(clearSelection()), CShortcut::keyClearSelection());
|
||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
||||
|
||||
// resizing
|
||||
menu.addAction(BlackMisc::CIcons::resize16(), "Full resize", this, SLOT(fullResizeToContents()));
|
||||
if (m_rowResizeMode == Interactive)
|
||||
@@ -216,6 +234,17 @@ namespace BlackGui
|
||||
this->setAcceptDrops(allowDrop);
|
||||
this->setDragEnabled(allowDrag);
|
||||
this->setDropIndicatorShown(allowDrop);
|
||||
CDropBase::allowDrop(allowDrop);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::allowDrop(bool allow)
|
||||
{
|
||||
this->allowDragDropValueObjects(this->dragEnabled(), allow);
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::isDropAllowed() const
|
||||
{
|
||||
return this->acceptDrops();
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::getHorizontalHeaderFontHeight() const
|
||||
@@ -441,6 +470,30 @@ namespace BlackGui
|
||||
this->update();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
if (!event) { return; }
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dropEvent(QDropEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CViewBase<ModelClass, ContainerType, ObjectType>::CViewBase(QWidget *parent, ModelClass *model) : CViewBaseNonTemplate(parent), m_model(model)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackgui/menudelegate.h"
|
||||
#include "blackgui/loadindicator.h"
|
||||
#include "blackgui/dropbase.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/worker.h"
|
||||
@@ -37,7 +38,9 @@ namespace BlackGui
|
||||
{
|
||||
//! Non templated base class, allows Q_OBJECT and signals / slots to be used
|
||||
class BLACKGUI_EXPORT CViewBaseNonTemplate :
|
||||
public QTableView, public BlackGui::Components::CEnableForDockWidgetInfoArea
|
||||
public QTableView,
|
||||
public BlackGui::Components::CEnableForDockWidgetInfoArea,
|
||||
public BlackGui::CDropBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -74,6 +77,15 @@ namespace BlackGui
|
||||
//! Allow to drag and/or drop value objects
|
||||
virtual void allowDragDropValueObjects(bool allowDrag, bool allowDrop);
|
||||
|
||||
//! \copydoc CDockWidget::allowDrop
|
||||
virtual void allowDrop(bool allow) override;
|
||||
|
||||
//! \copydoc CDockWidget::isDropAllowed
|
||||
virtual bool isDropAllowed() const override;
|
||||
|
||||
//! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea
|
||||
virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget);
|
||||
|
||||
//! Resize mode
|
||||
ResizeMode getResizeMode() const { return m_resizeMode; }
|
||||
|
||||
@@ -153,7 +165,7 @@ namespace BlackGui
|
||||
//! Number of elements changed
|
||||
void rowCountChanged(int count, bool withFilter);
|
||||
|
||||
// Model changed
|
||||
//! Model bas been changed
|
||||
void modelChanged();
|
||||
|
||||
//! Single object was changed in model
|
||||
@@ -201,6 +213,18 @@ namespace BlackGui
|
||||
//! \copydoc QTableView::showEvent
|
||||
virtual void showEvent(QShowEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragEnterEvent
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragMoveEvent
|
||||
virtual void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragLeaveEvent
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dropEvent
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
//! Perform resizing / non slot method for template
|
||||
virtual void performModeBasedResizeToContent() = 0;
|
||||
|
||||
@@ -239,10 +263,8 @@ namespace BlackGui
|
||||
bool m_acceptRowSelected = false; //!< selection changed
|
||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
const QKeySequence FilterKey {Qt::CTRL + Qt::Key_F}; //!< shortcut filter
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
|
||||
protected slots:
|
||||
|
||||
Reference in New Issue
Block a user