Graphic legend improvements using scroll area
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user