Skip to content

Commit

Permalink
menu refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
adisuciu committed Jun 21, 2024
1 parent e94143c commit 41adcae
Show file tree
Hide file tree
Showing 34 changed files with 556 additions and 269 deletions.
2 changes: 1 addition & 1 deletion gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ add_definitions(-DBOOST_ALL_DYN_LINK)
find_package(Boost COMPONENTS system filesystem thread chrono REQUIRED)

message(STATUS "Building " ${PROJECT_NAME})
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES} include/gui/widgets/compositewidget.h)
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES})

generate_export_header(
${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h
Expand Down
1 change: 1 addition & 0 deletions gui/include/gui/stylehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SCOPY_GUI_EXPORT StyleHelper : public QObject
static void MenuOnOffSwitchButton(SmallOnOffSwitch *w, QString objectName = "");
static void MenuCollapseSection(QWidget *w, QString objectName = "");
static void MenuCollapseHeaderLabel(QLabel *w, QString objectName = "");
static void MenuCollapseHeaderLineEdit(QLineEdit *w, QString objectName ="");
static void MenuComboLabel(QLabel *w, QString objectName = "");
static void MenuHeaderLabel(QLabel *w, QString objectName = "");
static void MenuControlLabel(QLabel *w, QString objectName = "");
Expand Down
7 changes: 7 additions & 0 deletions gui/include/gui/widgets/compositewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

#include <QWidget>

class Collapsable {
public:
virtual bool collapsed() = 0;
virtual void setCollapsed(bool b) = 0;

};

class CompositeWidget
{
public:
Expand Down
4 changes: 2 additions & 2 deletions gui/include/gui/widgets/menucollapsesection.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class SCOPY_GUI_EXPORT MenuCollapseHeader : public QAbstractButton
public:
MenuCollapseHeader(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent);
~MenuCollapseHeader();
QLabel *label();
QLineEdit *title();

private:
QAbstractButton *m_ctrl;
QLabel *m_label;
QLineEdit *m_label;
QHBoxLayout *lay;
};

Expand Down
23 changes: 18 additions & 5 deletions gui/include/gui/widgets/menucontrolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
#include <compositewidget.h>

namespace scopy {
class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton

class MenuControlButton;
class SCOPY_GUI_EXPORT MenuControlWidget {

public:
virtual MenuControlButton* header() = 0;
};

class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton, public MenuControlWidget
{
Q_OBJECT
QWIDGET_PAINT_EVENT_HELPER
Expand All @@ -32,14 +40,18 @@ class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton

void setColor(QColor c);
void setCheckBoxStyle(MenuControlButton::CheckboxStyle cs);
void setName(QString s);

void setDoubleClickToOpenMenu(bool b);
void setOpenMenuChecksThis(bool b);

QCheckBox *checkBox();
QPushButton *button();

MenuControlButton *header() override {return this;}

public Q_SLOTS:
void setName(QString s);

Q_SIGNALS:
void doubleClicked();

Expand All @@ -61,16 +73,17 @@ class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton
void mousePressEvent(QMouseEvent *event) override;
};

class SCOPY_GUI_EXPORT CollapsableMenuControlButton : public QWidget, public CompositeWidget
class SCOPY_GUI_EXPORT CollapsableMenuControlButton : public QWidget, public CompositeWidget, public MenuControlWidget
{
Q_OBJECT
public:
CollapsableMenuControlButton(QWidget *parent = nullptr);
~CollapsableMenuControlButton();

void add(QWidget *ch);
void remove(QWidget *ch);
void add(QWidget *ch) override;
void remove(QWidget *ch) override;
MenuControlButton *getControlBtn();
MenuControlButton *header() override {return m_ctrl;}

private:
MenuControlButton *m_ctrl;
Expand Down
4 changes: 2 additions & 2 deletions gui/include/gui/widgets/menuheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class SCOPY_GUI_EXPORT MenuHeaderWidget : public QWidget
MenuHeaderWidget(QString title, QPen pen, QWidget *parent = nullptr);
~MenuHeaderWidget();

QLabel *label();
QLineEdit *title();
void applyStylesheet();

private:
QLabel *m_label;
QLineEdit *m_title;
QFrame *m_line;
QPen m_pen;
};
Expand Down
26 changes: 26 additions & 0 deletions gui/include/gui/widgets/menusectionwidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef MENUSECTIONWIDGET_H
#define MENUSECTIONWIDGET_H
#include "compositewidget.h"
#include "menucollapsesection.h"
#include <QScrollArea>
#include <QVBoxLayout>
#include <QWidget>
Expand All @@ -8,6 +10,7 @@
#include <utils.h>

namespace scopy {

class SCOPY_GUI_EXPORT MenuSectionWidget : public QWidget
{
Q_OBJECT
Expand All @@ -34,5 +37,28 @@ class SCOPY_GUI_EXPORT MenuVScrollArea : public QScrollArea
QVBoxLayout *m_layout;
};

class SCOPY_GUI_EXPORT MenuSectionCollapseWidget : public QWidget, public Collapsable, public CompositeWidget {
Q_OBJECT
QWIDGET_PAINT_EVENT_HELPER
public:

MenuSectionCollapseWidget(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent = nullptr);
~MenuSectionCollapseWidget();
QVBoxLayout *contentLayout() const;

void add(QWidget *w) override;
void remove(QWidget *w) override;

bool collapsed() override;
void setCollapsed(bool b) override;
MenuCollapseSection* collapseSection();

private:
QVBoxLayout *m_layout;
MenuSectionWidget* m_section;
MenuCollapseSection *m_collapse;

};

} // namespace scopy
#endif // MENUSECTIONWIDGET_H
54 changes: 54 additions & 0 deletions gui/include/gui/widgets/menuwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef MENUWIDGET_H
#define MENUWIDGET_H

#include <QWidget>
#include "compositewidget.h"
#include "menuheader.h"
#include <QSpacerItem>
#include <QVBoxLayout>
#include <QMap>
#include <scopy-gui_export.h>

namespace scopy {
namespace gui {
class SCOPY_GUI_EXPORT MenuWidget : public QWidget, public CompositeWidget {
Q_OBJECT
public:

enum MenuAlignment
{
MA_TOPFIRST,
MA_TOPLAST,
MA_BOTTOMFIRST,
MA_BOTTOMLAST
};

MenuWidget(QString name, QPen p, QWidget *parent);
~MenuWidget();

void add(QWidget *, QString name, MenuAlignment position);
void add(QWidget *) override;
void remove(QWidget *) override;
void add(QWidget *, QString name);
void remove(QString);
MenuHeaderWidget* header();

QWidget* findWidget(QString name);
QString widgetName(QWidget*);

void collapseAll();
void setCollapsed(QString name, bool b);

private:
QMap<QString, QWidget*> m_widgetMap;
QSpacerItem *m_spacer;
QVBoxLayout *m_layScroll;
MenuHeaderWidget *m_header;
int uuid;

};
}

}

#endif // MENUWIDGET_H
2 changes: 2 additions & 0 deletions gui/src/plotchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ PlotChannel::PlotChannel(QString name, QPen pen, PlotAxis *xAxis, PlotAxis *yAxi
, m_handle(nullptr)
, m_pen(pen)
, m_name(name)
, m_style(0)
, m_thickness(1)

{

Expand Down
32 changes: 31 additions & 1 deletion gui/src/stylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ void StyleHelper::MenuSectionWidget(QWidget *w, QString objectName)
w->setObjectName(objectName);
w->layout()->setContentsMargins(10, 10, 10, 10);
QString style = QString(R"css(
scopy--MenuSectionWidget {background-color: &&UIElementBackground&&;
QWidget{ background-color: &&UIElementBackground&&;}
scopy--MenuSectionWidget {
border-radius: 4px;
margin-bottom: 3px;
}
Expand Down Expand Up @@ -991,6 +992,35 @@ void StyleHelper::MenuCollapseHeaderLabel(QLabel *w, QString objectName)
StyleHelper::MenuMediumLabel(w, objectName);
}

void StyleHelper::MenuCollapseHeaderLineEdit(QLineEdit *w, QString objectName)
{
if(!objectName.isEmpty())
w->setObjectName(objectName);
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
w->setMinimumWidth(50);
// lbl->setMaximumWidth(80);
QString style = QString(R"css(
QLineEdit {
color: white;
background-color: rgba(255,255,255,0);
font-weight: 500;
font-family: Open Sans;
font-size: 14px;
font-style: normal;
border: 0px solid gray;
border-bottom: 1px solid rgba(255, 255, 255, 102);
padding-left: -2px;
}
QLineEdit:disabled {
border: 0px solid gray;
border-bottom: 0px solid rgba(255, 255, 255, 102);
padding-left: -2px;
}
)css");
w->setStyleSheet(style);
}

void StyleHelper::MenuOnOffSwitchButton(SmallOnOffSwitch *w, QString objectName)
{
if(!objectName.isEmpty())
Expand Down
20 changes: 11 additions & 9 deletions gui/src/widgets/menucollapsesection.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "qlineedit.h"
#include <smallOnOffSwitch.h>
#include <widgets/menucollapsesection.h>

Expand All @@ -16,8 +17,13 @@ MenuCollapseHeader::MenuCollapseHeader(QString title, MenuCollapseSection::MenuH
setCheckable(true);
setLayout(lay);

m_label = new QLabel(title, this);
StyleHelper::MenuCollapseHeaderLabel(m_label, "menuCollapseLabel");
m_label = new QLineEdit(title, this);
m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
m_label->setEnabled(false);
m_label->setReadOnly(false);

StyleHelper::MenuCollapseHeaderLineEdit(m_label, "menuCollapseLabel");
m_label->setTextMargins(0,0,0,0);

switch(style) {
case MenuCollapseSection::MHCW_ARROW:
Expand All @@ -42,13 +48,13 @@ MenuCollapseHeader::MenuCollapseHeader(QString title, MenuCollapseSection::MenuH
m_ctrl->setAttribute(Qt::WA_TransparentForMouseEvents);

lay->addWidget(m_label);
lay->addSpacerItem(new QSpacerItem(40, 40, QSizePolicy::Expanding, QSizePolicy::Maximum));
lay->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Maximum));
lay->addWidget(m_ctrl);
}

MenuCollapseHeader::~MenuCollapseHeader() {}

QLabel *MenuCollapseHeader::label() { return m_label; }
QLineEdit *MenuCollapseHeader::title() { return m_label; }

MenuCollapseSection::MenuCollapseSection(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style,
QWidget *parent)
Expand Down Expand Up @@ -83,11 +89,7 @@ QString MenuCollapseSection::title() { return m_title; }
void MenuCollapseSection::setTitle(QString s)
{
m_title = s;
m_header->label()->setText(m_title);
m_header->title()->setText(m_title);
}

// void MenuCollapseSection::add(QWidget *ch) {
// m_contLayout->addWidget(ch);
//}

#include "moc_menucollapsesection.cpp"
12 changes: 8 additions & 4 deletions gui/src/widgets/menuheader.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "qlineedit.h"
#include <stylehelper.h>
#include <widgets/menuheader.h>

Expand All @@ -14,22 +15,25 @@ MenuHeaderWidget::MenuHeaderWidget(QString title, QPen pen, QWidget *parent)
lay->setMargin(3);
// lay->setContentsMargins(3,3,3,3);

m_label = new QLabel(title, this);
m_title = new QLineEdit(title, this);
m_title->setEnabled(false);
m_title->setReadOnly(false);

m_line = new QFrame(this);
m_pen = pen;

lay->addWidget(m_label);
lay->addWidget(m_title);
lay->addWidget(m_line);
applyStylesheet();
}

MenuHeaderWidget::~MenuHeaderWidget() {}

QLabel *MenuHeaderWidget::label() { return m_label; }
QLineEdit *MenuHeaderWidget::title() { return m_title; }

void MenuHeaderWidget::applyStylesheet()
{
StyleHelper::MenuHeaderLabel(m_label, "menuLabel");
StyleHelper::MenuCollapseHeaderLineEdit(m_title, "menuLabel");
StyleHelper::MenuHeaderLine(m_line, m_pen, "menuSeparator");
StyleHelper::MenuHeaderWidget(this, "menuHeader");
}
Expand Down
Loading

0 comments on commit 41adcae

Please sign in to comment.