Skip to content
Snippets Groups Projects
Commit 8e04c690 authored by m.puchner's avatar m.puchner
Browse files

Merge branch 'prep4_LayerEditor' into 'develop'

Further preparations for layer oriented sample editor

See merge request !404
parents 30b3a9a3 3c1fbb00
No related branches found
No related tags found
1 merge request!404Further preparations for layer oriented sample editor
Pipeline #47228 passed
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
// ************************************************************************************************ // ************************************************************************************************
#include "GroupBoxCollapser.h" #include "GroupBoxCollapser.h"
#include "GUI/Application/Application.h"
#include "GUI/Application/ApplicationSettings.h"
#include <QAction>
#include <QBoxLayout> #include <QBoxLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QToolButton> #include <QToolButton>
...@@ -32,11 +35,41 @@ GroupBoxCollapser* GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, b ...@@ -32,11 +35,41 @@ GroupBoxCollapser* GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, b
return p; return p;
} }
GroupBoxCollapser* GroupBoxCollapser::findInstalledCollapser(QGroupBox* groupBox)
{
if (groupBox == nullptr)
return nullptr;
return groupBox->findChild<GroupBoxCollapser*>();
}
void GroupBoxCollapser::setTitle(const QString& title) void GroupBoxCollapser::setTitle(const QString& title)
{ {
m_toggleButton->setText(title); m_toggleButton->setText(title);
} }
void GroupBoxCollapser::addAction(QAction* action)
{
auto btn = new QToolButton(m_titleWidget);
btn->setToolButtonStyle(Qt::ToolButtonIconOnly);
btn->setDefaultAction(action);
if (action->menu() != nullptr)
btn->setPopupMode(QToolButton::InstantPopup);
m_titleLayout->addWidget(btn);
connect(action, &QAction::changed, [=]() { btn->setVisible(action->isVisible()); });
}
void GroupBoxCollapser::addWidget(QWidget* widget)
{
m_titleLayout->addWidget(widget);
}
QWidget* GroupBoxCollapser::contentArea() const
{
return m_contentArea;
}
GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox) GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox)
{ {
QVBoxLayout* mainLayout = new QVBoxLayout; QVBoxLayout* mainLayout = new QVBoxLayout;
...@@ -44,6 +77,7 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox) ...@@ -44,6 +77,7 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox)
mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setContentsMargins(0, 0, 0, 0);
m_contentArea = new QWidget(groupBox); m_contentArea = new QWidget(groupBox);
m_contentArea->setObjectName("ContentArea");
m_contentArea->setLayout(groupBox->layout()); m_contentArea->setLayout(groupBox->layout());
mainLayout->addWidget(m_contentArea); mainLayout->addWidget(m_contentArea);
...@@ -51,15 +85,28 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox) ...@@ -51,15 +85,28 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox)
m_toggleButton = new QToolButton(groupBox); m_toggleButton = new QToolButton(groupBox);
m_toggleButton->setObjectName("GroupBoxToggler"); m_toggleButton->setObjectName("GroupBoxToggler");
m_toggleButton->setStyleSheet( if (baApp->currentStyle() == ApplicationSettings::Style::native)
"QToolButton { border: none; text-align: left; font: bold; padding: 5px}"); m_toggleButton->setStyleSheet(
"QToolButton { border: none; text-align: left; font: bold; padding: 5px}");
m_toggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); m_toggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_toggleButton->setCheckable(true); m_toggleButton->setCheckable(true);
m_toggleButton->setText(groupBox->title()); m_toggleButton->setText(groupBox->title());
m_toggleButton->setArrowType(Qt::ArrowType::DownArrow); m_toggleButton->setArrowType(Qt::ArrowType::DownArrow);
m_toggleButton->setChecked(true); m_toggleButton->setChecked(true);
m_toggleButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
m_titleWidget = new QWidget(groupBox);
m_titleWidget->setObjectName("GroupBoxTogglerTitleWidget");
m_titleWidget->setAttribute(Qt::WA_StyledBackground, true);
m_titleLayout = new QHBoxLayout;
m_titleLayout->setContentsMargins(0, 0, 3, 0);
m_titleLayout->setSpacing(3);
m_titleLayout->setAlignment(Qt::AlignVCenter);
m_titleWidget->setLayout(m_titleLayout);
m_titleLayout->addWidget(m_toggleButton);
groupBox->layout()->setMenuBar(m_toggleButton); groupBox->layout()->setMenuBar(m_titleWidget);
groupBox->setTitle(""); groupBox->setTitle("");
groupBox->setProperty("collapsible", true); // helps to distinguish GroupBoxes in stylesheets groupBox->setProperty("collapsible", true); // helps to distinguish GroupBoxes in stylesheets
......
...@@ -19,20 +19,46 @@ ...@@ -19,20 +19,46 @@
class QToolButton; class QToolButton;
class QGroupBox; class QGroupBox;
class QHBoxLayout;
class QAction;
//! Add-on to group boxes to make them collapsible.
//!
//! Also adds the possibility to show toolbuttons or widgets in the group box's title.
//! This add-on takes the layout (plus the contained widgets) of a given group box and moves it into
//! a newly created content area widget. A title widget will be added, and the original group box
//! title will be hidden.
//!
//! To support style sheets, the custom bool property "collapsible" will be added to the group box
//! an set to true.
class GroupBoxCollapser : public QObject { class GroupBoxCollapser : public QObject {
Q_OBJECT
public: public:
static GroupBoxCollapser* installIntoGroupBox(QGroupBox* groupBox, bool expanded = true); static GroupBoxCollapser* installIntoGroupBox(QGroupBox* groupBox, bool expanded = true);
static GroupBoxCollapser* findInstalledCollapser(QGroupBox* groupBox);
//! Set the title of the group box. Do not use the method groupBox->setTitle() any more once the
//! add-on is installed.
void setTitle(const QString& title); void setTitle(const QString& title);
//! Add a tool button to the title bar, connected to the given action
void addAction(QAction* action);
//! Add a widget to the title bar.
void addWidget(QWidget* widget);
//! The content area, to which the found group box content has been moved when the add-on has
//! been installed.
QWidget* contentArea() const;
private: private:
GroupBoxCollapser(QGroupBox* groupBox); GroupBoxCollapser(QGroupBox* groupBox);
void toggle(bool checked); void toggle(bool checked);
QToolButton* m_toggleButton; QWidget* m_titleWidget; //!< widget used to present the new groupbox title
QWidget* m_contentArea; QHBoxLayout* m_titleLayout; //!< layout in the title widget
QToolButton* m_toggleButton; //!< button to toggle between collapsed/expanded
QWidget* m_contentArea; //!< widget to where the original group box content has been moved
}; };
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// //
// BornAgain: simulate and fit reflection and scattering // BornAgain: simulate and fit reflection and scattering
// //
//! @file GUI/Views/CommonWidgets/TreeViewOverlayButtons.cpp //! @file GUI/Views/CommonWidgets/ItemViewOverlayButtons.cpp
//! @brief Implements class TreeViewOverlayButtons //! @brief Implements class ItemViewOverlayButtons
//! //!
//! @homepage http://www.bornagainproject.org //! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING) //! @license GNU General Public License v3 or higher (see COPYING)
...@@ -12,20 +12,20 @@ ...@@ -12,20 +12,20 @@
// //
// ************************************************************************************************ // ************************************************************************************************
#include "TreeViewOverlayButtons.h" #include "ItemViewOverlayButtons.h"
#include <QAbstractItemView>
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
#include <QBoxLayout> #include <QBoxLayout>
#include <QKeyEvent> #include <QKeyEvent>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QToolButton> #include <QToolButton>
#include <QTreeView>
namespace { namespace {
class TreeViewOverlayWidget : public QWidget { class ItemViewOverlayWidget : public QWidget {
public: public:
TreeViewOverlayWidget(QTreeView* parent, const QModelIndex& index); ItemViewOverlayWidget(QAbstractItemView* view, const QModelIndex& index);
static int heightForDelegate(); static int heightForDelegate();
...@@ -41,19 +41,19 @@ protected: ...@@ -41,19 +41,19 @@ protected:
private: private:
bool m_hover; bool m_hover;
QTreeView* m_tree; QAbstractItemView* m_view;
QModelIndex m_index; QModelIndex m_index;
Qt::Alignment m_horizontalAlignment; Qt::Alignment m_horizontalAlignment;
}; };
class TreeViewOverlayDelegate : public QStyledItemDelegate { class ItemViewOverlayDelegate : public QStyledItemDelegate {
public: public:
virtual QSize sizeHint(const QStyleOptionViewItem& option, virtual QSize sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const override const QModelIndex& index) const override
{ {
QSize s = QStyledItemDelegate::sizeHint(option, index); QSize s = QStyledItemDelegate::sizeHint(option, index);
if (index.parent().isValid()) { if (index.parent().isValid()) {
const int h = TreeViewOverlayWidget::heightForDelegate(); const int h = ItemViewOverlayWidget::heightForDelegate();
s.setHeight(std::max(s.height(), h)); s.setHeight(std::max(s.height(), h));
} }
...@@ -61,10 +61,10 @@ public: ...@@ -61,10 +61,10 @@ public:
} }
}; };
TreeViewOverlayWidget::TreeViewOverlayWidget(QTreeView* tree, const QModelIndex& index) ItemViewOverlayWidget::ItemViewOverlayWidget(QAbstractItemView* view, const QModelIndex& index)
: QWidget(tree) : QWidget(view)
, m_hover(false) , m_hover(false)
, m_tree(tree) , m_view(view)
, m_index(index) , m_index(index)
, m_horizontalAlignment(Qt::AlignRight) , m_horizontalAlignment(Qt::AlignRight)
{ {
...@@ -72,12 +72,12 @@ TreeViewOverlayWidget::TreeViewOverlayWidget(QTreeView* tree, const QModelIndex& ...@@ -72,12 +72,12 @@ TreeViewOverlayWidget::TreeViewOverlayWidget(QTreeView* tree, const QModelIndex&
setFocusPolicy(Qt::NoFocus); // do not receive keypress! setFocusPolicy(Qt::NoFocus); // do not receive keypress!
} }
void TreeViewOverlayWidget::setHover(bool b) void ItemViewOverlayWidget::setHover(bool b)
{ {
m_hover = b; m_hover = b;
} }
int TreeViewOverlayWidget::heightForDelegate() int ItemViewOverlayWidget::heightForDelegate()
{ {
QToolButton btn; QToolButton btn;
const int size = QApplication::style()->pixelMetric(QStyle::PM_ToolBarIconSize); const int size = QApplication::style()->pixelMetric(QStyle::PM_ToolBarIconSize);
...@@ -85,22 +85,22 @@ int TreeViewOverlayWidget::heightForDelegate() ...@@ -85,22 +85,22 @@ int TreeViewOverlayWidget::heightForDelegate()
return btn.sizeHint().height() + 6; // 3px on top and bottom return btn.sizeHint().height() + 6; // 3px on top and bottom
} }
void TreeViewOverlayWidget::enterEvent(QEvent*) void ItemViewOverlayWidget::enterEvent(QEvent*)
{ {
hover(true); hover(true);
} }
void TreeViewOverlayWidget::leaveEvent(QEvent*) void ItemViewOverlayWidget::leaveEvent(QEvent*)
{ {
hover(false); hover(false);
} }
void TreeViewOverlayWidget::mouseDoubleClickEvent(QMouseEvent* ev) void ItemViewOverlayWidget::mouseDoubleClickEvent(QMouseEvent* ev)
{ {
if (m_tree->editTriggers().testFlag(QAbstractItemView::DoubleClicked) if (m_view->editTriggers().testFlag(QAbstractItemView::DoubleClicked)
&& m_index.flags().testFlag(Qt::ItemIsEditable)) { && m_index.flags().testFlag(Qt::ItemIsEditable)) {
m_tree->setIndexWidget(m_index, nullptr); m_view->setIndexWidget(m_index, nullptr);
m_tree->edit(m_index); m_view->edit(m_index);
ev->accept(); ev->accept();
return; return;
} }
...@@ -108,7 +108,7 @@ void TreeViewOverlayWidget::mouseDoubleClickEvent(QMouseEvent* ev) ...@@ -108,7 +108,7 @@ void TreeViewOverlayWidget::mouseDoubleClickEvent(QMouseEvent* ev)
ev->ignore(); ev->ignore();
} }
void TreeViewOverlayWidget::create() void ItemViewOverlayWidget::create()
{ {
QHBoxLayout* h1 = new QHBoxLayout; QHBoxLayout* h1 = new QHBoxLayout;
...@@ -135,7 +135,7 @@ void TreeViewOverlayWidget::create() ...@@ -135,7 +135,7 @@ void TreeViewOverlayWidget::create()
} }
} }
void TreeViewOverlayWidget::hover(bool h) void ItemViewOverlayWidget::hover(bool h)
{ {
if (!m_hover) if (!m_hover)
return; return;
...@@ -151,81 +151,80 @@ void TreeViewOverlayWidget::hover(bool h) ...@@ -151,81 +151,80 @@ void TreeViewOverlayWidget::hover(bool h)
} }
} }
void TreeViewOverlayWidget::setHorizontalAlignment(Qt::Alignment a) void ItemViewOverlayWidget::setHorizontalAlignment(Qt::Alignment a)
{ {
m_horizontalAlignment = a; m_horizontalAlignment = a;
} }
} // namespace } // namespace
void TreeViewOverlayButtons::install(QTreeView* tree, FnGetActions fnGetActions) void ItemViewOverlayButtons::install(QAbstractItemView* view, FnGetActions fnGetActions)
{ {
TreeViewOverlayButtons* h = new TreeViewOverlayButtons(tree); ItemViewOverlayButtons* h = new ItemViewOverlayButtons(view);
h->m_getActions = fnGetActions; h->m_getActions = fnGetActions;
h->m_tree = tree; h->m_view = view;
auto d = new TreeViewOverlayDelegate; auto d = new ItemViewOverlayDelegate;
tree->setItemDelegate(d); view->setItemDelegate(d);
tree->installEventFilter(h); view->installEventFilter(h);
h->update(); h->update();
connect(d, &QAbstractItemDelegate::closeEditor, h, &TreeViewOverlayButtons::update); connect(d, &QAbstractItemDelegate::closeEditor, h, &ItemViewOverlayButtons::update);
connect(tree->model(), &QAbstractItemModel::modelReset, h, &TreeViewOverlayButtons::update, connect(view->model(), &QAbstractItemModel::modelReset, h, &ItemViewOverlayButtons::update,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(tree->model(), &QAbstractItemModel::rowsInserted, h, &TreeViewOverlayButtons::update, connect(view->model(), &QAbstractItemModel::rowsInserted, h, &ItemViewOverlayButtons::update,
Qt::QueuedConnection); // Queued: important! Qt::QueuedConnection); // Queued: important!
connect(tree->model(), &QAbstractItemModel::rowsRemoved, h, &TreeViewOverlayButtons::update, connect(view->model(), &QAbstractItemModel::rowsRemoved, h, &ItemViewOverlayButtons::update,
Qt::QueuedConnection); // Queued: important! Qt::QueuedConnection); // Queued: important!
} }
bool TreeViewOverlayButtons::eventFilter(QObject* obj, QEvent* event) bool ItemViewOverlayButtons::eventFilter(QObject* obj, QEvent* event)
{ {
// F2 would start the editing. Since OverlayWidgets are an editor already (indexWidget uses the // F2 would start the editing. Since OverlayWidgets are an editor already (indexWidget uses the
// editor internals), we remove the overlay at this place, so the tree will properly open the // editor internals), we remove the overlay at this place, so the view will properly open the
// editor // editor
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_F2) { if (keyEvent->key() == Qt::Key_F2) {
QModelIndex ci = m_tree->currentIndex(); QModelIndex ci = m_view->currentIndex();
if (ci.isValid() && ci.flags().testFlag(Qt::ItemIsEditable)) if (ci.isValid() && ci.flags().testFlag(Qt::ItemIsEditable))
m_tree->setIndexWidget(ci, nullptr); m_view->setIndexWidget(ci, nullptr);
} }
} }
return QObject::eventFilter(obj, event); return QObject::eventFilter(obj, event);
} }
TreeViewOverlayButtons::TreeViewOverlayButtons(QObject* parent) : QObject(parent) {} ItemViewOverlayButtons::ItemViewOverlayButtons(QObject* parent) : QObject(parent) {}
void TreeViewOverlayButtons::updateRecursive(const QModelIndex& index) void ItemViewOverlayButtons::updateRecursive(const QModelIndex& index)
{ {
const auto hoverIfNecessary = [&](QModelIndex index) { const auto hoverIfNecessary = [&](QModelIndex index) {
QPoint viewPortCoordinatesOfMouse = m_tree->mapFromGlobal(QCursor::pos()); QPoint viewPortCoordinatesOfMouse = m_view->mapFromGlobal(QCursor::pos());
if (m_tree->indexAt(viewPortCoordinatesOfMouse) == index) if (m_view->indexAt(viewPortCoordinatesOfMouse) == index)
if (auto* w = dynamic_cast<TreeViewOverlayWidget*>(m_tree->indexWidget(index))) if (auto* w = dynamic_cast<ItemViewOverlayWidget*>(m_view->indexWidget(index)))
w->hover(true); w->hover(true);
}; };
if (m_view->indexWidget(index) == nullptr)
if (m_tree->indexWidget(index) == nullptr)
installOverlay(index); installOverlay(index);
hoverIfNecessary(index); hoverIfNecessary(index);
auto m = m_tree->model(); auto m = m_view->model();
for (int childRow = 0; childRow < m->rowCount(index); childRow++) for (int childRow = 0; childRow < m->rowCount(index); childRow++)
updateRecursive(m->index(childRow, 0, index)); updateRecursive(m->index(childRow, 0, index));
} }
void TreeViewOverlayButtons::update() void ItemViewOverlayButtons::update()
{ {
if (m_tree->model() == nullptr) if (m_view->model() == nullptr)
return; return;
auto m = m_tree->model(); auto m = m_view->model();
for (int row = 0; row < m->rowCount(); row++) for (int row = 0; row < m->rowCount(); row++)
updateRecursive(m->index(row, 0)); updateRecursive(m->index(row, 0));
} }
void TreeViewOverlayButtons::installOverlay(const QModelIndex& index) void ItemViewOverlayButtons::installOverlay(const QModelIndex& index)
{ {
const auto permanentActions = m_getActions(index, false); const auto permanentActions = m_getActions(index, false);
const auto hoverActions = m_getActions(index, true); const auto hoverActions = m_getActions(index, true);
...@@ -233,7 +232,7 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index) ...@@ -233,7 +232,7 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index)
if (permanentActions.isEmpty() && hoverActions.isEmpty()) if (permanentActions.isEmpty() && hoverActions.isEmpty())
return; return;
auto w = new TreeViewOverlayWidget(m_tree, index); auto w = new ItemViewOverlayWidget(m_view, index);
const auto setAlignment = [&](const QList<QAction*> actions) { const auto setAlignment = [&](const QList<QAction*> actions) {
w->setHorizontalAlignment(Qt::AlignRight); w->setHorizontalAlignment(Qt::AlignRight);
...@@ -243,7 +242,6 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index) ...@@ -243,7 +242,6 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index)
w->setHorizontalAlignment(Qt::AlignLeft); w->setHorizontalAlignment(Qt::AlignLeft);
}; };
if (!permanentActions.isEmpty()) { if (!permanentActions.isEmpty()) {
setAlignment(permanentActions); setAlignment(permanentActions);
w->addActions(permanentActions); w->addActions(permanentActions);
...@@ -255,5 +253,5 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index) ...@@ -255,5 +253,5 @@ void TreeViewOverlayButtons::installOverlay(const QModelIndex& index)
} }
w->create(); w->create();
m_tree->setIndexWidget(index, w); m_view->setIndexWidget(index, w);
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// //
// BornAgain: simulate and fit reflection and scattering // BornAgain: simulate and fit reflection and scattering
// //
//! @file GUI/Views/CommonWidgets/TreeViewOverlayButtons.h //! @file GUI/Views/CommonWidgets/ItemViewOverlayButtons.h
//! @brief Defines class TreeViewOverlayButtons //! @brief Defines class ItemViewOverlayButtons
//! //!
//! @homepage http://www.bornagainproject.org //! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING) //! @license GNU General Public License v3 or higher (see COPYING)
...@@ -18,27 +18,27 @@ ...@@ -18,27 +18,27 @@
#include <QObject> #include <QObject>
#include <functional> #include <functional>
class QTreeView;
class QAction; class QAction;
class QAbstractItemView;
class TreeViewOverlayButtons : public QObject { class ItemViewOverlayButtons : public QObject {
Q_OBJECT Q_OBJECT
public: public:
typedef std::function<QList<QAction*>(const QModelIndex&, bool)> FnGetActions; typedef std::function<QList<QAction*>(const QModelIndex&, bool)> FnGetActions;
static void install(QTreeView* tree, FnGetActions fnGetActions); static void install(QAbstractItemView* view, FnGetActions fnGetActions);
protected: protected:
bool eventFilter(QObject* obj, QEvent* event) override; bool eventFilter(QObject* obj, QEvent* event) override;
private: private:
TreeViewOverlayButtons(QObject* parent); ItemViewOverlayButtons(QObject* parent);
void updateRecursive(const QModelIndex& index); void updateRecursive(const QModelIndex& index);
void update(); void update();
void installOverlay(const QModelIndex& index); void installOverlay(const QModelIndex& index);
FnGetActions m_getActions; FnGetActions m_getActions;
QTreeView* m_tree; QAbstractItemView* m_view;
}; };
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#include "GUI/Models/RealDataItem.h" #include "GUI/Models/RealDataItem.h"
#include "GUI/Models/RealDataModel.h" #include "GUI/Models/RealDataModel.h"
#include "GUI/Views/CommonWidgets/GUIHelpers.h" #include "GUI/Views/CommonWidgets/GUIHelpers.h"
#include "GUI/Views/CommonWidgets/ItemViewOverlayButtons.h"
#include "GUI/Views/CommonWidgets/StyledToolBar.h" #include "GUI/Views/CommonWidgets/StyledToolBar.h"
#include "GUI/Views/CommonWidgets/TreeViewOverlayButtons.h"
#include "GUI/Views/ImportDataWidgets/ImportDataUtils.h" #include "GUI/Views/ImportDataWidgets/ImportDataUtils.h"
#include "GUI/Views/ImportDataWidgets/RealDataPropertiesWidget.h" #include "GUI/Views/ImportDataWidgets/RealDataPropertiesWidget.h"
#include "GUI/Views/ImportDataWidgets/RealDataTreeModel.h" #include "GUI/Views/ImportDataWidgets/RealDataTreeModel.h"
...@@ -129,7 +129,7 @@ RealDataSelectorWidget::RealDataSelectorWidget(QWidget* parent, ProjectDocument* ...@@ -129,7 +129,7 @@ RealDataSelectorWidget::RealDataSelectorWidget(QWidget* parent, ProjectDocument*
if (currentItem()) if (currentItem())
emit selectionChanged(currentItem()); emit selectionChanged(currentItem());
TreeViewOverlayButtons::install( ItemViewOverlayButtons::install(
m_itemTree, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); m_itemTree, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); });
} }
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "GUI/Views/InstrumentWidgets/InstrumentLibraryEditor.h" #include "GUI/Views/InstrumentWidgets/InstrumentLibraryEditor.h"
#include "GUI/Application/Application.h" #include "GUI/Application/Application.h"
#include "GUI/Models/InstrumentItems.h" #include "GUI/Models/InstrumentItems.h"
#include "GUI/Views/CommonWidgets/ItemViewOverlayButtons.h"
#include "GUI/Views/CommonWidgets/StyleUtils.h" #include "GUI/Views/CommonWidgets/StyleUtils.h"
#include "GUI/Views/CommonWidgets/TreeViewOverlayButtons.h"
#include "GUI/mainwindow/mainwindow.h" #include "GUI/mainwindow/mainwindow.h"
#include "GUI/utils/ItemDelegateForHTML.h" #include "GUI/utils/ItemDelegateForHTML.h"
#include "ui_InstrumentLibraryEditor.h" #include "ui_InstrumentLibraryEditor.h"
...@@ -92,7 +92,7 @@ InstrumentItem* InstrumentLibraryEditor::execChoose() ...@@ -92,7 +92,7 @@ InstrumentItem* InstrumentLibraryEditor::execChoose()
{ {
setWindowTitle("Instrument Library - Choose instrument"); setWindowTitle("Instrument Library - Choose instrument");
TreeViewOverlayButtons::install( ItemViewOverlayButtons::install(
m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); });
m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this));
...@@ -119,7 +119,7 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd) ...@@ -119,7 +119,7 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd)
m_treeModel->setNewInstrument(addedInstrument); m_treeModel->setNewInstrument(addedInstrument);
m_treeModel->setTypeEnabled(TreeModel::instrumentType(addedInstrument), true); m_treeModel->setTypeEnabled(TreeModel::instrumentType(addedInstrument), true);
TreeViewOverlayButtons::install( ItemViewOverlayButtons::install(
m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); });
m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this));
......
...@@ -45,13 +45,13 @@ QWidget[stylable="true"] QTreeView ...@@ -45,13 +45,13 @@ QWidget[stylable="true"] QTreeView
border: none; border: none;
} }
QTreeView QToolButton QAbstractItemView QToolButton
{ {
border-radius: 3px; border-radius: 3px;
border: 1px solid; border: 1px solid;
} }
QTreeView QToolButton:hover QAbstractItemView QToolButton:hover
{ {
border-radius: 4px; border-radius: 4px;
border: 2px solid; border: 2px solid;
......
...@@ -72,19 +72,19 @@ QWidget[stylable="true"] .QPushButton:pressed ...@@ -72,19 +72,19 @@ QWidget[stylable="true"] .QPushButton:pressed
background: rgb(218,248,255); background: rgb(218,248,255);
} }
QTreeView QToolButton QAbstractItemView QToolButton
{ {
background: rgb(188,218,233); background: rgb(188,218,233);
border-color:rgb(50,119,152); border-color:rgb(50,119,152);
} }
QTreeView QToolButton:hover QAbstractItemView QToolButton:hover
{ {
background: rgb(208,238,252); background: rgb(208,238,252);
border-color:rgb(50,119,152); border-color:rgb(50,119,152);
} }
QTreeView QToolButton:pressed QAbstractItemView QToolButton:pressed
{ {
background: rgb(218,248,255); background: rgb(218,248,255);
border-color:rgb(50,119,152); border-color:rgb(50,119,152);
......
...@@ -33,11 +33,6 @@ ItemDelegateForHTML::ItemDelegateForHTML(QObject* parent) : QStyledItemDelegate( ...@@ -33,11 +33,6 @@ ItemDelegateForHTML::ItemDelegateForHTML(QObject* parent) : QStyledItemDelegate(
void ItemDelegateForHTML::paint(QPainter* painter, const QStyleOptionViewItem& option, void ItemDelegateForHTML::paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const const QModelIndex& index) const
{ {
if (!index.parent().isValid()) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
QStyleOptionViewItem options = option; QStyleOptionViewItem options = option;
initStyleOption(&options, index); initStyleOption(&options, index);
if (!hasHtml(options.text)) { if (!hasHtml(options.text)) {
...@@ -79,18 +74,17 @@ QSize ItemDelegateForHTML::sizeHint(const QStyleOptionViewItem& option, ...@@ -79,18 +74,17 @@ QSize ItemDelegateForHTML::sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const const QModelIndex& index) const
{ {
QSize s = QStyledItemDelegate::sizeHint(option, index); QSize s = QStyledItemDelegate::sizeHint(option, index);
if (!index.parent().isValid())
return s;
// get size of parent; this is the minimum size // get size of parent; this is the minimum size
const int h = QStyledItemDelegate::sizeHint(option, index.parent()).height(); const int h = QStyledItemDelegate::sizeHint(option, index).height();
s.setHeight(std::max(s.height(), h)); s.setHeight(std::max(s.height(), h));
QStyleOptionViewItem options = option; QStyleOptionViewItem options = option;
initStyleOption(&options, index); initStyleOption(&options, index);
auto s2 = sizeHint(options.text); auto s2 = sizeHint(options.text);
s.setHeight(std::max(s.height(), s2.height())); s.setHeight(std::max(s.height(), s2.height() + 10));
s.setWidth(s2.width() + h); // +h: icon
return s; return s;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment