Graphic legend improvements using scroll area
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(qad)
|
project(qad)
|
||||||
set(qad_MAJOR 1)
|
set(qad_MAJOR 1)
|
||||||
set(qad_MINOR 17)
|
set(qad_MINOR 17)
|
||||||
set(qad_REVISION 0)
|
set(qad_REVISION 1)
|
||||||
set(qad_SUFFIX )
|
set(qad_SUFFIX )
|
||||||
set(qad_COMPANY SHS)
|
set(qad_COMPANY SHS)
|
||||||
set(qad_DOMAIN org.SHS)
|
set(qad_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <QPanGesture>
|
#include <QPanGesture>
|
||||||
#include <QPinchGesture>
|
#include <QPinchGesture>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QTimer>
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||||
# include <QRandomGenerator>
|
# include <QRandomGenerator>
|
||||||
#endif
|
#endif
|
||||||
@@ -25,6 +27,28 @@ const double rad2deg_qpie = 45. / atan(1.);
|
|||||||
|
|
||||||
__GraphicRegistrator__ __graphic_registrator__;
|
__GraphicRegistrator__ __graphic_registrator__;
|
||||||
|
|
||||||
|
class LegendScrollArea: public QScrollArea {
|
||||||
|
public:
|
||||||
|
LegendScrollArea(QWidget * w): QScrollArea() {
|
||||||
|
setFrameShape(QFrame::NoFrame);
|
||||||
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
setWidgetResizable(true);
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
||||||
|
setWidget(w);
|
||||||
|
viewport()->setAutoFillBackground(false);
|
||||||
|
w->setAutoFillBackground(false);
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
virtual QSize sizeHint() const {
|
||||||
|
QSize ret;
|
||||||
|
if (!widget()) return ret;
|
||||||
|
ret = widget()->sizeHint();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) {
|
Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) {
|
||||||
canvas_gl = 0;
|
canvas_gl = 0;
|
||||||
@@ -39,6 +63,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
|||||||
#endif
|
#endif
|
||||||
ui = new Ui::Graphic();
|
ui = new Ui::Graphic();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend));
|
||||||
|
ui->scrollLegend->hide();
|
||||||
QActionGroup * agroup = new QActionGroup(this);
|
QActionGroup * agroup = new QActionGroup(this);
|
||||||
agroup->addAction(ui->graphic_actionGuidesFree );
|
agroup->addAction(ui->graphic_actionGuidesFree );
|
||||||
agroup->addAction(ui->graphic_actionGuidesTraceX);
|
agroup->addAction(ui->graphic_actionGuidesTraceX);
|
||||||
@@ -143,7 +169,12 @@ void Graphic::changeEvent(QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void Graphic::resizeEvent(QResizeEvent *) {
|
void Graphic::resizeEvent(QResizeEvent *) {
|
||||||
if (leg_update) updateLegend(false);
|
if (leg_update)
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||||
|
QTimer::singleShot(0, this, [this](){updateLegend(false);});
|
||||||
|
#else
|
||||||
|
updateLegend(false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1530,7 +1561,7 @@ void Graphic::updateLegend(bool es) {
|
|||||||
p.end();
|
p.end();
|
||||||
graphics[i].icon = QIcon(pix);
|
graphics[i].icon = QIcon(pix);
|
||||||
}
|
}
|
||||||
if (!ui->widgetLegend->isVisibleTo(this)) {
|
if (!ui->scrollLegend->isVisibleTo(this)) {
|
||||||
if (es) emit graphicSettingsChanged();
|
if (es) emit graphicSettingsChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1564,15 +1595,18 @@ void Graphic::updateLegend(bool es) {
|
|||||||
}
|
}
|
||||||
int maxcol = qMax<int>(ui->widgetLegend->width() / ps - 1, 1);
|
int maxcol = qMax<int>(ui->widgetLegend->width() / ps - 1, 1);
|
||||||
int row = 0, col = 0;
|
int row = 0, col = 0;
|
||||||
bool lv = ui->widgetLegend->isVisibleTo(this);
|
bool lv = ui->scrollLegend->isVisibleTo(this);
|
||||||
ui->widgetLegend->hide();
|
ui->scrollLegend->hide();
|
||||||
for (int i = 0; i < graphics.size(); i++) {
|
for (int i = 0; i < graphics.size(); i++) {
|
||||||
ui->layoutLegend->addWidget(graphics[i].pb,row,col);
|
ui->layoutLegend->addWidget(graphics[i].pb,row,col);
|
||||||
graphics[i].pb->show();
|
graphics[i].pb->show();
|
||||||
col++;
|
col++;
|
||||||
if (col > maxcol) {col = 0; row++;}
|
if (col > maxcol) {col = 0; row++;}
|
||||||
}
|
}
|
||||||
ui->widgetLegend->setVisible(lv);
|
ui->gridLayout->invalidate();
|
||||||
|
ui->scrollLegend->setVisible(lv);
|
||||||
|
ui->scrollLegend->layout()->itemAt(0)->widget()->updateGeometry();
|
||||||
|
//ui->gridLayout->invalidate();
|
||||||
leg_update = true;
|
leg_update = true;
|
||||||
if (es) emit graphicSettingsChanged();
|
if (es) emit graphicSettingsChanged();
|
||||||
}
|
}
|
||||||
@@ -1672,7 +1706,7 @@ bool Graphic::statusVisible() const {
|
|||||||
|
|
||||||
|
|
||||||
bool Graphic::legendVisible() const {
|
bool Graphic::legendVisible() const {
|
||||||
return ui->widgetLegend->isVisible();
|
return ui->scrollLegend->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1777,9 +1811,13 @@ void Graphic::setStatusVisible(bool visible) {
|
|||||||
|
|
||||||
|
|
||||||
void Graphic::setLegendVisible(bool visible) {
|
void Graphic::setLegendVisible(bool visible) {
|
||||||
ui->widgetLegend->setVisible(visible);
|
ui->scrollLegend->setVisible(visible);
|
||||||
ui->graphic_checkLegend->setChecked(visible);
|
ui->graphic_checkLegend->setChecked(visible);
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||||
|
QTimer::singleShot(0, this, [this](){updateLegend();});
|
||||||
|
#else
|
||||||
updateLegend();
|
updateLegend();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>564</width>
|
<width>564</width>
|
||||||
<height>433</height>
|
<height>484</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
@@ -32,6 +32,16 @@
|
|||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="labelCaption">
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0" rowspan="2">
|
<item row="0" column="0" rowspan="2">
|
||||||
<widget class="QWidget" name="widgetLeft" native="true">
|
<widget class="QWidget" name="widgetLeft" native="true">
|
||||||
<widget class="QWidget" name="layoutWidget">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
@@ -216,7 +226,7 @@
|
|||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>0</width>
|
||||||
<height>79</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
@@ -225,19 +235,16 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLabel" name="labelCaption">
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::RichText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2" rowspan="2">
|
<item row="0" column="2" rowspan="2">
|
||||||
<widget class="QWidget" name="widgetRight" native="true"/>
|
<widget class="QWidget" name="widgetRight" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLabel" name="status">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cursor: ( ; )</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QFrame" name="frame">
|
<widget class="QFrame" name="frame">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -359,39 +366,44 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QWidget" name="widgetLegend" native="true">
|
||||||
|
<layout class="QGridLayout" name="layoutLegend">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalSpacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLabel" name="status">
|
|
||||||
<property name="text">
|
|
||||||
<string>Cursor: ( ; )</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QWidget" name="widgetLegend" native="true">
|
<widget class="QWidget" name="scrollLegend" native="true">
|
||||||
<property name="minimumSize">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="layoutLegend">
|
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
|
||||||
<property name="horizontalSpacing">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
</property>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
Reference in New Issue
Block a user