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)
|
||||
set(qad_MAJOR 1)
|
||||
set(qad_MINOR 17)
|
||||
set(qad_REVISION 0)
|
||||
set(qad_REVISION 1)
|
||||
set(qad_SUFFIX )
|
||||
set(qad_COMPANY SHS)
|
||||
set(qad_DOMAIN org.SHS)
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <QPanGesture>
|
||||
#include <QPinchGesture>
|
||||
#include <QActionGroup>
|
||||
#include <QScrollArea>
|
||||
#include <QTimer>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
# include <QRandomGenerator>
|
||||
#endif
|
||||
@@ -25,6 +27,28 @@ const double rad2deg_qpie = 45. / atan(1.);
|
||||
|
||||
__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) {
|
||||
canvas_gl = 0;
|
||||
@@ -39,6 +63,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
#endif
|
||||
ui = new Ui::Graphic();
|
||||
ui->setupUi(this);
|
||||
ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend));
|
||||
ui->scrollLegend->hide();
|
||||
QActionGroup * agroup = new QActionGroup(this);
|
||||
agroup->addAction(ui->graphic_actionGuidesFree );
|
||||
agroup->addAction(ui->graphic_actionGuidesTraceX);
|
||||
@@ -143,7 +169,12 @@ void Graphic::changeEvent(QEvent * e) {
|
||||
|
||||
|
||||
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();
|
||||
graphics[i].icon = QIcon(pix);
|
||||
}
|
||||
if (!ui->widgetLegend->isVisibleTo(this)) {
|
||||
if (!ui->scrollLegend->isVisibleTo(this)) {
|
||||
if (es) emit graphicSettingsChanged();
|
||||
return;
|
||||
}
|
||||
@@ -1564,15 +1595,18 @@ void Graphic::updateLegend(bool es) {
|
||||
}
|
||||
int maxcol = qMax<int>(ui->widgetLegend->width() / ps - 1, 1);
|
||||
int row = 0, col = 0;
|
||||
bool lv = ui->widgetLegend->isVisibleTo(this);
|
||||
ui->widgetLegend->hide();
|
||||
bool lv = ui->scrollLegend->isVisibleTo(this);
|
||||
ui->scrollLegend->hide();
|
||||
for (int i = 0; i < graphics.size(); i++) {
|
||||
ui->layoutLegend->addWidget(graphics[i].pb,row,col);
|
||||
graphics[i].pb->show();
|
||||
col++;
|
||||
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;
|
||||
if (es) emit graphicSettingsChanged();
|
||||
}
|
||||
@@ -1672,7 +1706,7 @@ bool Graphic::statusVisible() 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) {
|
||||
ui->widgetLegend->setVisible(visible);
|
||||
ui->scrollLegend->setVisible(visible);
|
||||
ui->graphic_checkLegend->setChecked(visible);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
QTimer::singleShot(0, this, [this](){updateLegend();});
|
||||
#else
|
||||
updateLegend();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>564</width>
|
||||
<height>433</height>
|
||||
<height>484</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@@ -32,6 +32,16 @@
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</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">
|
||||
<widget class="QWidget" name="widgetLeft" native="true">
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
@@ -216,7 +226,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>79</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@@ -225,19 +235,16 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QWidget" name="widgetRight" native="true"/>
|
||||
</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">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
@@ -359,39 +366,44 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QWidget" name="widgetLegend" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="layoutLegend">
|
||||
<widget class="QWidget" name="scrollLegend" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>4</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user