Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+89305
-100020
No files matched your search
Executable → Regular
+64
-73
@@ -1,131 +1,122 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_image_cropper.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsItem>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsImageCropper::LtsImageCropper(QWidget *parent, const QSize &size, const QPixmap &pixmap)
|
||||
: QGraphicsView(parent)
|
||||
, m_scene(new QGraphicsScene(this))
|
||||
, m_maxScale(2.0f)
|
||||
, m_multiplier(1.0f)
|
||||
LtsImageCropper::LtsImageCropper(QWidget* parent, const QSize& size, const QPixmap& pixmap)
|
||||
: QGraphicsView(parent), m_scene(new QGraphicsScene(this)), m_maxScale(2.0f), m_multiplier(1.0f)
|
||||
{
|
||||
if(!size.isNull())
|
||||
setFixedSize(size);
|
||||
if (!size.isNull())
|
||||
setFixedSize(size);
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
|
||||
m_scene->setBackgroundBrush(Qt::Dense6Pattern);
|
||||
setScene(m_scene);
|
||||
m_scene->setBackgroundBrush(Qt::Dense6Pattern);
|
||||
setScene(m_scene);
|
||||
|
||||
setPixmap(pixmap);
|
||||
setPixmap(pixmap);
|
||||
}
|
||||
|
||||
LtsImageCropper::~LtsImageCropper()
|
||||
{
|
||||
delete m_pixmapItem;
|
||||
delete m_pixmapItem;
|
||||
}
|
||||
|
||||
void LtsImageCropper::setPixmap(const QPixmap &pixmap)
|
||||
void LtsImageCropper::setPixmap(const QPixmap& pixmap)
|
||||
{
|
||||
if(pixmap.isNull())
|
||||
return;
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
delete m_pixmapItem;
|
||||
delete m_pixmapItem;
|
||||
|
||||
m_pixmapItem = new QGraphicsPixmapItem(pixmap);
|
||||
m_scene->addItem(m_pixmapItem);
|
||||
m_pixmapItem = new QGraphicsPixmapItem(pixmap);
|
||||
m_scene->addItem(m_pixmapItem);
|
||||
|
||||
setTransform(QTransform());
|
||||
m_currentZoom = 1.0;
|
||||
setTransform(QTransform());
|
||||
m_currentZoom = 1.0;
|
||||
|
||||
|
||||
double sx = static_cast<double>(size().height()) / pixmap.height();
|
||||
double sy = static_cast<double>(size().width()) / pixmap.width();
|
||||
if(sx > 1 )
|
||||
scale(sx,sx);
|
||||
if(sy > 1)
|
||||
scale(sy,sy);
|
||||
double sx = static_cast<double>(size().height()) / pixmap.height();
|
||||
double sy = static_cast<double>(size().width()) / pixmap.width();
|
||||
if (sx > 1)
|
||||
scale(sx, sx);
|
||||
if (sy > 1)
|
||||
scale(sy, sy);
|
||||
|
||||
|
||||
double ratioWidth = 1.0 * size().width() / pixmap.width();
|
||||
double ratioHeight = 1.0 * size().height() / pixmap.height();
|
||||
m_minScale = qMax(ratioHeight,ratioWidth);
|
||||
double ratioWidth = 1.0 * size().width() / pixmap.width();
|
||||
double ratioHeight = 1.0 * size().height() / pixmap.height();
|
||||
m_minScale = qMax(ratioHeight, ratioWidth);
|
||||
|
||||
calculateScaleStep();
|
||||
calculateScaleStep();
|
||||
|
||||
|
||||
m_scene->setSceneRect(pixmap.rect());
|
||||
centerOn(m_scene->sceneRect().center());
|
||||
m_scene->setSceneRect(pixmap.rect());
|
||||
centerOn(m_scene->sceneRect().center());
|
||||
}
|
||||
|
||||
void LtsImageCropper::setImage(const QImage &image)
|
||||
void LtsImageCropper::setImage(const QImage& image)
|
||||
{
|
||||
setPixmap(QPixmap::fromImage(image));
|
||||
setPixmap(QPixmap::fromImage(image));
|
||||
}
|
||||
|
||||
void LtsImageCropper::setMultiplier(double multiplier)
|
||||
{
|
||||
m_multiplier = multiplier;
|
||||
calculateScaleStep();
|
||||
m_multiplier = multiplier;
|
||||
calculateScaleStep();
|
||||
}
|
||||
|
||||
void LtsImageCropper::calculateScaleStep()
|
||||
{
|
||||
m_stepScale = (m_maxScale - m_minScale) / 100.0;
|
||||
m_stepScale = (m_maxScale - m_minScale) / 100.0;
|
||||
}
|
||||
|
||||
QImage LtsImageCropper::image()
|
||||
{
|
||||
return grab().toImage();
|
||||
return grab().toImage();
|
||||
}
|
||||
|
||||
void LtsImageCropper::wheelEvent(QWheelEvent *event)
|
||||
void LtsImageCropper::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
if(!m_pixmapItem)
|
||||
return;
|
||||
if (!m_pixmapItem)
|
||||
return;
|
||||
|
||||
auto value = event->pixelDelta();
|
||||
if(value.isNull())
|
||||
value = event->angleDelta() / 15.0;
|
||||
auto value = event->pixelDelta();
|
||||
if (value.isNull())
|
||||
value = event->angleDelta() / 15.0;
|
||||
|
||||
|
||||
double scrollZoom = m_stepScale * value.y() * m_multiplier / 8.0;
|
||||
double scrollZoom = m_stepScale * value.y() * m_multiplier / 8.0;
|
||||
|
||||
m_currentZoom += scrollZoom;
|
||||
m_currentZoom += scrollZoom;
|
||||
|
||||
if(m_currentZoom > m_maxScale)
|
||||
m_currentZoom = m_maxScale;
|
||||
else if (m_currentZoom < m_minScale)
|
||||
m_currentZoom = m_minScale;
|
||||
if (m_currentZoom > m_maxScale)
|
||||
m_currentZoom = m_maxScale;
|
||||
else if (m_currentZoom < m_minScale)
|
||||
m_currentZoom = m_minScale;
|
||||
|
||||
|
||||
setTransform(QTransform(m_currentZoom, transform().m12(), transform().m13(),
|
||||
transform().m21(), m_currentZoom, transform().m23(),
|
||||
transform().m31(), transform().m32(), 1));
|
||||
setTransform(QTransform(m_currentZoom, transform().m12(), transform().m13(), transform().m21(), m_currentZoom,
|
||||
transform().m23(), transform().m31(), transform().m32(), 1));
|
||||
}
|
||||
|
||||
void LtsImageCropper::mousePressEvent(QMouseEvent *event)
|
||||
void LtsImageCropper::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::DragMoveCursor);
|
||||
update();
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
QApplication::setOverrideCursor(Qt::DragMoveCursor);
|
||||
update();
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void LtsImageCropper::mouseReleaseEvent(QMouseEvent *event)
|
||||
void LtsImageCropper::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
update();
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
QApplication::restoreOverrideCursor();
|
||||
update();
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+43
-53
@@ -1,81 +1,71 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsImageCropper : public QGraphicsView
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QPixmap pixMap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
||||
Q_PROPERTY(double maxZoom READ maxZoom WRITE setMaxZoom)
|
||||
Q_PROPERTY(QPixmap pixMap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
||||
Q_PROPERTY(double maxZoom READ maxZoom WRITE setMaxZoom)
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
LtsImageCropper(QWidget* parent = nullptr, const QSize& size = {}, const QPixmap& pixmap = {});
|
||||
~LtsImageCropper();
|
||||
|
||||
LtsImageCropper(QWidget *parent = nullptr, const QSize &size = {} , const QPixmap &pixmap = {});
|
||||
~LtsImageCropper();
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
|
||||
|
||||
void setImage(const QImage& image);
|
||||
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
void setMultiplier(double multiplier);
|
||||
|
||||
|
||||
void setMaxZoom(double maxZoom)
|
||||
{
|
||||
m_maxScale = maxZoom;
|
||||
}
|
||||
|
||||
void setImage(const QImage &image);
|
||||
QPixmap pixmap()
|
||||
{
|
||||
return grab();
|
||||
}
|
||||
|
||||
|
||||
QImage image();
|
||||
|
||||
void setMultiplier(double multiplier);
|
||||
double multiplier() const
|
||||
{
|
||||
return m_multiplier;
|
||||
}
|
||||
|
||||
|
||||
double maxZoom() const
|
||||
{
|
||||
return m_maxScale;
|
||||
}
|
||||
|
||||
void setMaxZoom(double maxZoom) { m_maxScale = maxZoom; }
|
||||
private:
|
||||
QGraphicsScene* m_scene = nullptr;
|
||||
QGraphicsPixmapItem* m_pixmapItem = nullptr;
|
||||
|
||||
|
||||
double m_currentZoom;
|
||||
double m_minScale;
|
||||
double m_maxScale;
|
||||
double m_stepScale;
|
||||
double m_multiplier;
|
||||
|
||||
QPixmap pixmap() { return grab(); }
|
||||
|
||||
|
||||
|
||||
QImage image();
|
||||
|
||||
|
||||
|
||||
double multiplier() const { return m_multiplier; }
|
||||
|
||||
|
||||
|
||||
double maxZoom() const { return m_maxScale; }
|
||||
|
||||
private:
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsPixmapItem *m_pixmapItem = nullptr;
|
||||
|
||||
double m_currentZoom;
|
||||
double m_minScale;
|
||||
double m_maxScale;
|
||||
double m_stepScale;
|
||||
double m_multiplier;
|
||||
|
||||
void calculateScaleStep();
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void calculateScaleStep();
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+28
-59
@@ -1,90 +1,59 @@
|
||||
#ifndef LTS_ABSTRACT_SEQUENCE_WIDGET_H
|
||||
#define LTS_ABSTRACT_SEQUENCE_WIDGET_H
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QList>
|
||||
#include "ltswidgets_export.h"
|
||||
#include <QObject>
|
||||
|
||||
class QToolButton;
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsAbstractSequenceWidget : public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsAbstractSequenceWidget(QWidget* parent = nullptr, const bool& readOnly = false);
|
||||
|
||||
~LtsAbstractSequenceWidget();
|
||||
|
||||
explicit LtsAbstractSequenceWidget(QWidget *parent = nullptr, const bool &readOnly = false);
|
||||
virtual void addWidget(QWidget* widget, bool isReadOnly, bool isButtonVisible = true);
|
||||
|
||||
~LtsAbstractSequenceWidget();
|
||||
virtual void getValue(QWidget* contentType, const QString& findObjectName) const;
|
||||
|
||||
|
||||
virtual void setMemberCount(int count);
|
||||
|
||||
virtual void addWidget(QWidget* widget, bool isReadOnly, bool isButtonVisible = true);
|
||||
|
||||
virtual uint32_t getMemberCount() const;
|
||||
|
||||
virtual void getValue(QWidget *contentType,
|
||||
const QString &findObjectName) const;
|
||||
virtual int getMemberlistSize();
|
||||
|
||||
|
||||
protected:
|
||||
virtual QToolButton* pbAddMember() const;
|
||||
|
||||
virtual void setMemberCount(int count);
|
||||
virtual QString getObjectName(int index) const;
|
||||
|
||||
|
||||
virtual void setupMemberWidget(QWidget* child, QToolButton* pbChild, const QString& objectName,
|
||||
bool isButtonVisible = true) = 0;
|
||||
|
||||
virtual uint32_t getMemberCount() const;
|
||||
signals:
|
||||
|
||||
|
||||
void addMember();
|
||||
|
||||
virtual int getMemberlistSize();
|
||||
private slots:
|
||||
|
||||
virtual void addMemberWidget(QWidget* member, bool isReadOnly, bool isButtonVisible = true);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
virtual QToolButton *pbAddMember() const;
|
||||
|
||||
|
||||
|
||||
|
||||
virtual QString getObjectName(int index) const;
|
||||
|
||||
|
||||
|
||||
virtual void setupMemberWidget(QWidget *child, QToolButton *pbChild, const QString &objectName, bool isButtonVisible = true) = 0;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
void addMember();
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
virtual void addMemberWidget(QWidget *member, bool isReadOnly, bool isButtonVisible = true);
|
||||
|
||||
|
||||
|
||||
virtual void deleteMemberWidget(QObject *member);
|
||||
|
||||
private:
|
||||
bool m_readOnly;
|
||||
QToolButton *m_pbAddMember = nullptr;
|
||||
QList<QWidget*> m_memberList;
|
||||
|
||||
virtual void deleteMemberWidget(QObject* member);
|
||||
|
||||
private:
|
||||
bool m_readOnly;
|
||||
QToolButton* m_pbAddMember = nullptr;
|
||||
QList<QWidget*> m_memberList;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+243
-265
@@ -1,286 +1,264 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_base.h"
|
||||
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include <memory>
|
||||
#include <QVector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class LtsAbstractTableModel : public QAbstractTableModel
|
||||
template <class T> class LtsAbstractTableModel : public QAbstractTableModel
|
||||
{
|
||||
public:
|
||||
LtsAbstractTableModel(const QVector<QString> &header, QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, m_vecColumns(header)
|
||||
{}
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section>= 0 && section < m_vecColumns.size())
|
||||
return m_vecColumns[section];
|
||||
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
bool isEmpty(const QModelIndex &parent = QModelIndex())
|
||||
{
|
||||
return parent.isValid() ? true : m_vecData.isEmpty();
|
||||
}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||||
{
|
||||
return parent.isValid() ? 0 : m_vecData.size();
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override
|
||||
{
|
||||
return parent.isValid() ? 0 : m_vecColumns.size();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_vecData.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
bool indexIsValid(const QModelIndex &idx) const
|
||||
{
|
||||
if (!idx.isValid())
|
||||
return false;
|
||||
if (idx.row() < 0 || idx.row() >= m_vecData.size())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool removeRow(int row)
|
||||
{
|
||||
return removeRows(row, 1);
|
||||
}
|
||||
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return false;
|
||||
|
||||
int range = std::min(row + count, m_vecData.size());
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, range - 1);
|
||||
m_vecData.erase(m_vecData.begin() + row, m_vecData.begin() + range);
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool insertRow(const T &item)
|
||||
{
|
||||
if (isFiltered(item, DataModification::eAdded) || isDeletedInternal(item))
|
||||
return false;
|
||||
beginInsertRows(QModelIndex(), m_vecData.size(), m_vecData.size());
|
||||
m_vecData.append(item);
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename CONT>
|
||||
void insertRows(const CONT &items)
|
||||
{
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
const int cntBefore = m_vecData.size();
|
||||
for (const auto &item : items)
|
||||
{
|
||||
if (isFiltered(item, DataModification::eAdded) || isDeletedInternal(item))
|
||||
continue;
|
||||
m_vecData += item;
|
||||
}
|
||||
const int cntAfter = m_vecData.size();
|
||||
if (cntBefore == cntAfter)
|
||||
return;
|
||||
beginInsertRows(QModelIndex(), cntBefore, cntAfter - 1);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void setData(const QVector<T> &vecData)
|
||||
{
|
||||
clear();
|
||||
insertRows(vecData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void update()
|
||||
{
|
||||
if (!m_vecData.isEmpty())
|
||||
emit dataChanged(index(0, 0), index(m_vecData.size() - 1, columnCount() - 1));
|
||||
}
|
||||
|
||||
T getRowData(int row) const
|
||||
{
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return T();
|
||||
return m_vecData.at(row);
|
||||
}
|
||||
|
||||
bool setRowData(int row, const T &data)
|
||||
{
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return false;
|
||||
|
||||
m_vecData[row] = data;
|
||||
emit dataChanged(index(row, 0), index(row, columnCount() - 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
QModelIndex findIndexForId(int id, int column = 0) const
|
||||
{
|
||||
const int row = findRowForId(id);
|
||||
if (row < 0)
|
||||
return QModelIndex();
|
||||
return index(row, column);
|
||||
}
|
||||
|
||||
int getId(const QModelIndex &mi) const
|
||||
{
|
||||
if (!indexIsValid(mi))
|
||||
return -1;
|
||||
return getIdInternal(m_vecData.at(mi.row()));
|
||||
}
|
||||
|
||||
protected:
|
||||
template <class C>
|
||||
class HasId
|
||||
{
|
||||
template <class CLS>
|
||||
static std::true_type testSignature(const int &(CLS::*)() const);
|
||||
template <class CLS>
|
||||
static std::true_type testSignature(int (CLS::*)() const);
|
||||
|
||||
template <class CLS>
|
||||
static decltype(testSignature(&CLS::id)) test(std::nullptr_t);
|
||||
|
||||
template <class CLS>
|
||||
static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
|
||||
template <typename F = T, typename std::enable_if<HasId<F>::value, int>::type = 0>
|
||||
int getIdInternal(const F &data) const
|
||||
{
|
||||
return data.id();
|
||||
}
|
||||
|
||||
|
||||
virtual int getId(const T &data) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
template < typename F = T, typename std::enable_if < !HasId<F>::value, int>::type = 0>
|
||||
int getIdInternal(const F &data) const
|
||||
{
|
||||
return getId(data);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
class HasIsDeleted
|
||||
{
|
||||
template <class CLS>
|
||||
static std::true_type testSignature(const bool &(CLS::*)() const);
|
||||
template <class CLS>
|
||||
static std::true_type testSignature(bool (CLS::*)() const);
|
||||
|
||||
template <class CLS>
|
||||
static decltype(testSignature(&CLS::isDeleted)) test(std::nullptr_t);
|
||||
|
||||
template <class CLS>
|
||||
static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
template <typename F = T, typename std::enable_if<HasIsDeleted<F>::value, int>::type = 0>
|
||||
bool isDeletedInternal(const F &data) const
|
||||
{
|
||||
return data.isDeleted();
|
||||
}
|
||||
|
||||
virtual int isDeleted(const T &data) const
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
return false;
|
||||
}
|
||||
template < typename F = T, typename std::enable_if < !HasIsDeleted<F>::value, int>::type = 0>
|
||||
bool isDeletedInternal(const F &data) const
|
||||
{
|
||||
return isDeleted(data);
|
||||
}
|
||||
|
||||
|
||||
virtual bool isFiltered(const T &data, DataModification modType) const
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(modType);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
virtual bool onDataChanged(const T &data, DataModification modType)
|
||||
{
|
||||
if (isFiltered(data, modType))
|
||||
return false;
|
||||
|
||||
const int id = getIdInternal(data);
|
||||
const int row = findRowForId(id);
|
||||
|
||||
|
||||
if (modType == DataModification::eRemoved || isDeletedInternal(data))
|
||||
LtsAbstractTableModel(const QVector<QString>& header, QObject* parent)
|
||||
: QAbstractTableModel(parent), m_vecColumns(header)
|
||||
{
|
||||
if (row >= 0)
|
||||
return removeRow(row);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (modType == DataModification::eAdded && row < 0)
|
||||
return insertRow(data);
|
||||
|
||||
return setRowData(row, data);
|
||||
}
|
||||
|
||||
int findRowForId(int id) const
|
||||
{
|
||||
for (int i = 0; i < m_vecData.size(); ++i)
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
|
||||
{
|
||||
if (getIdInternal(m_vecData.at(i)) == id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section >= 0 && section < m_vecColumns.size())
|
||||
return m_vecColumns[section];
|
||||
|
||||
QVector<T> m_vecData;
|
||||
QVector<QString> m_vecColumns;
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
bool isEmpty(const QModelIndex& parent = QModelIndex())
|
||||
{
|
||||
return parent.isValid() ? true : m_vecData.isEmpty();
|
||||
}
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override
|
||||
{
|
||||
return parent.isValid() ? 0 : m_vecData.size();
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override
|
||||
{
|
||||
return parent.isValid() ? 0 : m_vecColumns.size();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_vecData.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
bool indexIsValid(const QModelIndex& idx) const
|
||||
{
|
||||
if (!idx.isValid())
|
||||
return false;
|
||||
if (idx.row() < 0 || idx.row() >= m_vecData.size())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool removeRow(int row)
|
||||
{
|
||||
return removeRows(row, 1);
|
||||
}
|
||||
|
||||
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return false;
|
||||
|
||||
int range = std::min(row + count, m_vecData.size());
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, range - 1);
|
||||
m_vecData.erase(m_vecData.begin() + row, m_vecData.begin() + range);
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool insertRow(const T& item)
|
||||
{
|
||||
if (isFiltered(item, DataModification::eAdded) || isDeletedInternal(item))
|
||||
return false;
|
||||
beginInsertRows(QModelIndex(), m_vecData.size(), m_vecData.size());
|
||||
m_vecData.append(item);
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename CONT> void insertRows(const CONT& items)
|
||||
{
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
const int cntBefore = m_vecData.size();
|
||||
for (const auto& item : items)
|
||||
{
|
||||
if (isFiltered(item, DataModification::eAdded) || isDeletedInternal(item))
|
||||
continue;
|
||||
m_vecData += item;
|
||||
}
|
||||
const int cntAfter = m_vecData.size();
|
||||
if (cntBefore == cntAfter)
|
||||
return;
|
||||
beginInsertRows(QModelIndex(), cntBefore, cntAfter - 1);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void setData(const QVector<T>& vecData)
|
||||
{
|
||||
clear();
|
||||
insertRows(vecData);
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
if (!m_vecData.isEmpty())
|
||||
emit dataChanged(index(0, 0), index(m_vecData.size() - 1, columnCount() - 1));
|
||||
}
|
||||
|
||||
T getRowData(int row) const
|
||||
{
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return T();
|
||||
return m_vecData.at(row);
|
||||
}
|
||||
|
||||
bool setRowData(int row, const T& data)
|
||||
{
|
||||
if (row < 0 || row >= m_vecData.size())
|
||||
return false;
|
||||
|
||||
m_vecData[row] = data;
|
||||
emit dataChanged(index(row, 0), index(row, columnCount() - 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
QModelIndex findIndexForId(int id, int column = 0) const
|
||||
{
|
||||
const int row = findRowForId(id);
|
||||
if (row < 0)
|
||||
return QModelIndex();
|
||||
return index(row, column);
|
||||
}
|
||||
|
||||
int getId(const QModelIndex& mi) const
|
||||
{
|
||||
if (!indexIsValid(mi))
|
||||
return -1;
|
||||
return getIdInternal(m_vecData.at(mi.row()));
|
||||
}
|
||||
|
||||
protected:
|
||||
template <class C> class HasId
|
||||
{
|
||||
template <class CLS> static std::true_type testSignature(const int& (CLS::*)() const);
|
||||
template <class CLS> static std::true_type testSignature(int (CLS::*)() const);
|
||||
|
||||
template <class CLS> static decltype(testSignature(&CLS::id)) test(std::nullptr_t);
|
||||
|
||||
template <class CLS> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
template <typename F = T, typename std::enable_if<HasId<F>::value, int>::type = 0>
|
||||
int getIdInternal(const F& data) const
|
||||
{
|
||||
return data.id();
|
||||
}
|
||||
|
||||
virtual int getId(const T& data) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
template <typename F = T, typename std::enable_if<!HasId<F>::value, int>::type = 0>
|
||||
int getIdInternal(const F& data) const
|
||||
{
|
||||
return getId(data);
|
||||
}
|
||||
|
||||
template <class C> class HasIsDeleted
|
||||
{
|
||||
template <class CLS> static std::true_type testSignature(const bool& (CLS::*)() const);
|
||||
template <class CLS> static std::true_type testSignature(bool (CLS::*)() const);
|
||||
|
||||
template <class CLS> static decltype(testSignature(&CLS::isDeleted)) test(std::nullptr_t);
|
||||
|
||||
template <class CLS> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
template <typename F = T, typename std::enable_if<HasIsDeleted<F>::value, int>::type = 0>
|
||||
bool isDeletedInternal(const F& data) const
|
||||
{
|
||||
return data.isDeleted();
|
||||
}
|
||||
|
||||
virtual int isDeleted(const T& data) const
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename F = T, typename std::enable_if<!HasIsDeleted<F>::value, int>::type = 0>
|
||||
bool isDeletedInternal(const F& data) const
|
||||
{
|
||||
return isDeleted(data);
|
||||
}
|
||||
|
||||
virtual bool isFiltered(const T& data, DataModification modType) const
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(modType);
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool onDataChanged(const T& data, DataModification modType)
|
||||
{
|
||||
if (isFiltered(data, modType))
|
||||
return false;
|
||||
|
||||
const int id = getIdInternal(data);
|
||||
const int row = findRowForId(id);
|
||||
|
||||
if (modType == DataModification::eRemoved || isDeletedInternal(data))
|
||||
{
|
||||
if (row >= 0)
|
||||
return removeRow(row);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (modType == DataModification::eAdded && row < 0)
|
||||
return insertRow(data);
|
||||
|
||||
return setRowData(row, data);
|
||||
}
|
||||
|
||||
int findRowForId(int id) const
|
||||
{
|
||||
for (int i = 0; i < m_vecData.size(); ++i)
|
||||
{
|
||||
if (getIdInternal(m_vecData.at(i)) == id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QVector<T> m_vecData;
|
||||
QVector<QString> m_vecColumns;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+145
-159
@@ -1,247 +1,233 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_angle_edit.h"
|
||||
#include <utility>
|
||||
|
||||
#include "ui_lts_angle_edit.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
inline constexpr double pi() { return M_PI; }
|
||||
inline constexpr double deg2rad() { return pi() / 180.; }
|
||||
inline constexpr double rad2deg() { return 1. / deg2rad(); }
|
||||
inline constexpr double pi()
|
||||
{
|
||||
return M_PI;
|
||||
}
|
||||
|
||||
inline constexpr double deg2rad()
|
||||
{
|
||||
return pi() / 180.;
|
||||
}
|
||||
|
||||
inline constexpr double rad2deg()
|
||||
{
|
||||
return 1. / deg2rad();
|
||||
}
|
||||
|
||||
constexpr int maxAngleDeg = 360;
|
||||
constexpr int maxAngleMil = 6400;
|
||||
constexpr std::tuple<int,int,int,int> c_limDeg (0, maxAngleDeg,0, 10);
|
||||
constexpr std::tuple<int,int,int, int> c_limMil(0, maxAngleMil,0, 50);
|
||||
constexpr std::tuple<int,int,int, int> c_limRad(-99999, 99999, 3, 1);
|
||||
constexpr std::tuple<int, int, int, int> c_limDeg(0, maxAngleDeg, 0, 10);
|
||||
constexpr std::tuple<int, int, int, int> c_limMil(0, maxAngleMil, 0, 50);
|
||||
constexpr std::tuple<int, int, int, int> c_limRad(-99999, 99999, 3, 1);
|
||||
|
||||
inline constexpr double mil2Deg(const double &mil)
|
||||
inline constexpr double mil2Deg(const double& mil)
|
||||
{
|
||||
return maxAngleDeg * mil / maxAngleMil;
|
||||
}
|
||||
inline constexpr double deg2Mil(const double &angleDeg)
|
||||
{
|
||||
return maxAngleMil * angleDeg / maxAngleDeg;
|
||||
}
|
||||
inline constexpr double deg2Rad(const double &angleDeg)
|
||||
{
|
||||
return angleDeg * deg2rad();
|
||||
}
|
||||
inline constexpr double rad2Degree(const double &angleRad)
|
||||
{
|
||||
return angleRad * 180/pi();
|
||||
}
|
||||
inline constexpr double mil2Rad(const double &mil)
|
||||
{
|
||||
return deg2Rad(mil2Deg(mil));
|
||||
}
|
||||
inline constexpr double rad2Mil(const double &angleRad)
|
||||
{
|
||||
return deg2Mil(rad2Degree(angleRad));
|
||||
return maxAngleDeg * mil / maxAngleMil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LtsAngleEdit::LtsAngleEdit(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(new Ui_LtsAngleEdit)
|
||||
inline constexpr double deg2Mil(const double& angleDeg)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
return maxAngleMil * angleDeg / maxAngleDeg;
|
||||
}
|
||||
|
||||
inline constexpr double deg2Rad(const double& angleDeg)
|
||||
{
|
||||
return angleDeg * deg2rad();
|
||||
}
|
||||
|
||||
inline constexpr double rad2Degree(const double& angleRad)
|
||||
{
|
||||
return angleRad * 180 / pi();
|
||||
}
|
||||
|
||||
inline constexpr double mil2Rad(const double& mil)
|
||||
{
|
||||
return deg2Rad(mil2Deg(mil));
|
||||
}
|
||||
|
||||
inline constexpr double rad2Mil(const double& angleRad)
|
||||
{
|
||||
return deg2Mil(rad2Degree(angleRad));
|
||||
}
|
||||
|
||||
LtsAngleEdit::LtsAngleEdit(QWidget* parent) : QWidget(parent), m_ui(new Ui_LtsAngleEdit)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
}
|
||||
|
||||
LtsAngleEdit::~LtsAngleEdit()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::initAngleEditWidget(const unsigned int sboxCount)
|
||||
{
|
||||
|
||||
m_dboxLimitMap.insert(AngleUnitType::Deg, c_limDeg);
|
||||
m_dboxLimitMap.insert(AngleUnitType::Mil, c_limMil);
|
||||
m_dboxLimitMap.insert(AngleUnitType::Rad, c_limRad);
|
||||
m_hiddenUnits.clear();
|
||||
m_hiddenUnits.insert((int)AngleUnitType::Rad);
|
||||
|
||||
|
||||
for(unsigned int i=0; i<sboxCount; ++i)
|
||||
{
|
||||
QSharedPointer<QDoubleSpinBox> spinbox = QSharedPointer<QDoubleSpinBox>(new QDoubleSpinBox(this) );
|
||||
spinbox->setValue(0);
|
||||
spinbox->setAlignment(Qt::AlignRight);
|
||||
spinbox->setMinimumWidth(91);
|
||||
|
||||
spinbox.data()->setObjectName(spinBoxName+QString::number(m_sBoxMap.count()));
|
||||
m_ui->hLayoutSpinbox->addWidget(spinbox.data(), 0);
|
||||
m_sBoxMap.insert(m_sBoxMap.count(), spinbox);
|
||||
}
|
||||
m_ui->hLayoutSpinbox->setContentsMargins(1,1,1,1);
|
||||
m_dboxLimitMap.insert(AngleUnitType::Deg, c_limDeg);
|
||||
m_dboxLimitMap.insert(AngleUnitType::Mil, c_limMil);
|
||||
m_dboxLimitMap.insert(AngleUnitType::Rad, c_limRad);
|
||||
m_hiddenUnits.clear();
|
||||
m_hiddenUnits.insert((int)AngleUnitType::Rad);
|
||||
|
||||
for (unsigned int i = 0; i < sboxCount; ++i)
|
||||
{
|
||||
QSharedPointer<QDoubleSpinBox> spinbox = QSharedPointer<QDoubleSpinBox>(new QDoubleSpinBox(this));
|
||||
spinbox->setValue(0);
|
||||
spinbox->setAlignment(Qt::AlignRight);
|
||||
spinbox->setMinimumWidth(91);
|
||||
|
||||
|
||||
connect(m_ui->cBoxAngleUnit, qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this, &LtsAngleEdit::onCBoxAngleUnitChanged);
|
||||
spinbox.data()->setObjectName(spinBoxName + QString::number(m_sBoxMap.count()));
|
||||
m_ui->hLayoutSpinbox->addWidget(spinbox.data(), 0);
|
||||
m_sBoxMap.insert(m_sBoxMap.count(), spinbox);
|
||||
}
|
||||
m_ui->hLayoutSpinbox->setContentsMargins(1, 1, 1, 1);
|
||||
|
||||
setCboxUnit();
|
||||
|
||||
connect(m_ui->cBoxAngleUnit, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
&LtsAngleEdit::onCBoxAngleUnitChanged);
|
||||
|
||||
setCboxUnit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::setValue(const double value, unsigned int dboxIndex)
|
||||
{
|
||||
if ((int)dboxIndex > m_sBoxMap.count())
|
||||
return;
|
||||
auto spinbox = m_sBoxMap.value(dboxIndex);
|
||||
spinbox->setValue(value);
|
||||
if ((int)dboxIndex > m_sBoxMap.count())
|
||||
return;
|
||||
auto spinbox = m_sBoxMap.value(dboxIndex);
|
||||
spinbox->setValue(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::setValue(const double value, AngleUnitType valueUnit, unsigned int dboxIndex)
|
||||
{
|
||||
setValue(getAngleConverted(value, getAngleCurrentUnit(), valueUnit),dboxIndex);
|
||||
setValue(getAngleConverted(value, getAngleCurrentUnit(), valueUnit), dboxIndex);
|
||||
}
|
||||
|
||||
void LtsAngleEdit::hideUnits(const QVector<AngleUnitType> &list)
|
||||
void LtsAngleEdit::hideUnits(const QVector<AngleUnitType>& list)
|
||||
{
|
||||
for(auto u : list)
|
||||
m_hiddenUnits.insert((int)u);
|
||||
setCboxUnit();
|
||||
for (auto u : list)
|
||||
m_hiddenUnits.insert((int)u);
|
||||
setCboxUnit();
|
||||
}
|
||||
|
||||
void LtsAngleEdit::showUnits(const QVector<AngleUnitType> &list)
|
||||
void LtsAngleEdit::showUnits(const QVector<AngleUnitType>& list)
|
||||
{
|
||||
for (const auto &u : list)
|
||||
m_hiddenUnits.remove((int)u);
|
||||
setCboxUnit();
|
||||
for (const auto& u : list)
|
||||
m_hiddenUnits.remove((int)u);
|
||||
setCboxUnit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::setCboxUnit()
|
||||
{
|
||||
m_ui->cBoxAngleUnit->clear();
|
||||
const std::vector<AngleUnitType> allUnits = {AngleUnitType::Deg, AngleUnitType::Mil, AngleUnitType::Rad};
|
||||
for(const auto &u : allUnits)
|
||||
{
|
||||
if (m_hiddenUnits.contains((int)u))
|
||||
continue;
|
||||
m_ui->cBoxAngleUnit->insertItem(static_cast<int>(u), toString(u),static_cast<int>(u));
|
||||
}
|
||||
m_ui->cBoxAngleUnit->clear();
|
||||
const std::vector<AngleUnitType> allUnits = {AngleUnitType::Deg, AngleUnitType::Mil, AngleUnitType::Rad};
|
||||
for (const auto& u : allUnits)
|
||||
{
|
||||
if (m_hiddenUnits.contains((int)u))
|
||||
continue;
|
||||
m_ui->cBoxAngleUnit->insertItem(static_cast<int>(u), toString(u), static_cast<int>(u));
|
||||
}
|
||||
|
||||
setAngleUnit(AngleUnitType::Deg);
|
||||
setAngleUnit(AngleUnitType::Deg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::setValue(const double value, AngleUnitType valueUnit)
|
||||
{
|
||||
|
||||
setValue(getAngleConverted(value, getAngleCurrentUnit(), valueUnit),0);
|
||||
|
||||
setValue(getAngleConverted(value, getAngleCurrentUnit(), valueUnit), 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsAngleEdit::setAngleUnit(const AngleUnitType &type)
|
||||
void LtsAngleEdit::setAngleUnit(const AngleUnitType& type)
|
||||
{
|
||||
m_ui->cBoxAngleUnit->setCurrentIndex(static_cast<int>(type));
|
||||
m_ui->cBoxAngleUnit->setCurrentIndex(static_cast<int>(type));
|
||||
}
|
||||
|
||||
|
||||
|
||||
LtsAngleEdit::AngleUnitType LtsAngleEdit::getAngleCurrentUnit() const
|
||||
{
|
||||
return static_cast<AngleUnitType>(m_ui->cBoxAngleUnit->currentIndex());
|
||||
return static_cast<AngleUnitType>(m_ui->cBoxAngleUnit->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
|
||||
double LtsAngleEdit::getAngle(unsigned int sboxIndex) const
|
||||
{
|
||||
if ((int)sboxIndex > m_sBoxMap.count())
|
||||
return 0;
|
||||
auto spinbox = m_sBoxMap.value(sboxIndex);
|
||||
return spinbox->value();
|
||||
if ((int)sboxIndex > m_sBoxMap.count())
|
||||
return 0;
|
||||
auto spinbox = m_sBoxMap.value(sboxIndex);
|
||||
return spinbox->value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString LtsAngleEdit::toString(LtsAngleEdit::AngleUnitType t)
|
||||
{
|
||||
switch(t)
|
||||
{
|
||||
case AngleUnitType::Deg:
|
||||
return tr("Degree");
|
||||
case AngleUnitType::Mil:
|
||||
return tr("Mil");
|
||||
case AngleUnitType::Rad:
|
||||
return tr("Radian");
|
||||
default:
|
||||
switch (t)
|
||||
{
|
||||
case AngleUnitType::Deg:
|
||||
return tr("Degree");
|
||||
case AngleUnitType::Mil:
|
||||
return tr("Mil");
|
||||
case AngleUnitType::Rad:
|
||||
return tr("Radian");
|
||||
default:
|
||||
return tr("");
|
||||
}
|
||||
return tr("");
|
||||
}
|
||||
return tr("");
|
||||
}
|
||||
|
||||
void LtsAngleEdit::onCBoxAngleUnitChanged()
|
||||
{
|
||||
AngleUnitType newUnit = static_cast<AngleUnitType>(m_ui->cBoxAngleUnit->currentData().toInt());
|
||||
for(auto dbox : std::as_const(m_sBoxMap))
|
||||
{
|
||||
const double value = getAngleConverted(dbox->value(), newUnit, m_currAngleUnit);
|
||||
auto mapVal = m_dboxLimitMap.value(newUnit);
|
||||
dbox->setMinimum(std::get<LimTuple::AngleMin>(mapVal));
|
||||
dbox->setMaximum(std::get<LimTuple::AngleMax>(mapVal));
|
||||
dbox->setDecimals(std::get<LimTuple::DecimalPlace>(mapVal));
|
||||
dbox->setSingleStep(std::get<LimTuple::SingleStep>(mapVal));
|
||||
dbox->setValue(value);
|
||||
}
|
||||
m_currAngleUnit = newUnit;
|
||||
AngleUnitType newUnit = static_cast<AngleUnitType>(m_ui->cBoxAngleUnit->currentData().toInt());
|
||||
for (auto dbox : std::as_const(m_sBoxMap))
|
||||
{
|
||||
const double value = getAngleConverted(dbox->value(), newUnit, m_currAngleUnit);
|
||||
auto mapVal = m_dboxLimitMap.value(newUnit);
|
||||
dbox->setMinimum(std::get<LimTuple::AngleMin>(mapVal));
|
||||
dbox->setMaximum(std::get<LimTuple::AngleMax>(mapVal));
|
||||
dbox->setDecimals(std::get<LimTuple::DecimalPlace>(mapVal));
|
||||
dbox->setSingleStep(std::get<LimTuple::SingleStep>(mapVal));
|
||||
dbox->setValue(value);
|
||||
}
|
||||
m_currAngleUnit = newUnit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double LtsAngleEdit::getAngleConverted(const double angle, LtsAngleEdit::AngleUnitType newAngleUnit, LtsAngleEdit::AngleUnitType oldAngleUnit)
|
||||
double LtsAngleEdit::getAngleConverted(const double angle, LtsAngleEdit::AngleUnitType newAngleUnit,
|
||||
LtsAngleEdit::AngleUnitType oldAngleUnit)
|
||||
{
|
||||
double convertedAngle = angle;
|
||||
if (oldAngleUnit == AngleUnitType::Deg && newAngleUnit == AngleUnitType::Mil )
|
||||
convertedAngle = deg2Mil(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Deg && newAngleUnit == AngleUnitType::Rad )
|
||||
convertedAngle = deg2Rad(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Mil && newAngleUnit == AngleUnitType::Deg )
|
||||
convertedAngle = mil2Deg(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Mil && newAngleUnit == AngleUnitType::Rad )
|
||||
convertedAngle = mil2Rad(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Rad && newAngleUnit == AngleUnitType::Deg )
|
||||
convertedAngle = rad2Degree(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Rad && newAngleUnit == AngleUnitType::Mil )
|
||||
convertedAngle = rad2Mil(angle);
|
||||
double convertedAngle = angle;
|
||||
if (oldAngleUnit == AngleUnitType::Deg && newAngleUnit == AngleUnitType::Mil)
|
||||
convertedAngle = deg2Mil(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Deg && newAngleUnit == AngleUnitType::Rad)
|
||||
convertedAngle = deg2Rad(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Mil && newAngleUnit == AngleUnitType::Deg)
|
||||
convertedAngle = mil2Deg(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Mil && newAngleUnit == AngleUnitType::Rad)
|
||||
convertedAngle = mil2Rad(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Rad && newAngleUnit == AngleUnitType::Deg)
|
||||
convertedAngle = rad2Degree(angle);
|
||||
else if (oldAngleUnit == AngleUnitType::Rad && newAngleUnit == AngleUnitType::Mil)
|
||||
convertedAngle = rad2Mil(angle);
|
||||
|
||||
return convertedAngle;
|
||||
return convertedAngle;
|
||||
}
|
||||
|
||||
void LtsAngleEdit::setEnable(int sbIndex, bool enabled)
|
||||
{
|
||||
if ((int)sbIndex > m_sBoxMap.count())
|
||||
return;
|
||||
m_sBoxMap.value(sbIndex)->setEnabled(enabled);
|
||||
if ((int)sbIndex > m_sBoxMap.count())
|
||||
return;
|
||||
m_sBoxMap.value(sbIndex)->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void LtsAngleEdit::showSpinbox(int sbIndex, bool visible)
|
||||
{
|
||||
if ((int)sbIndex > m_sBoxMap.count())
|
||||
return;
|
||||
m_sBoxMap.value(sbIndex)->setVisible(visible);
|
||||
}
|
||||
|
||||
if ((int)sbIndex > m_sBoxMap.count())
|
||||
return;
|
||||
m_sBoxMap.value(sbIndex)->setVisible(visible);
|
||||
}
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+39
-50
@@ -1,72 +1,61 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSet>
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QWidget>
|
||||
|
||||
class Ui_LtsAngleEdit;
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsAngleEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsAngleEdit(QWidget *parent = nullptr);
|
||||
~LtsAngleEdit();
|
||||
public:
|
||||
explicit LtsAngleEdit(QWidget* parent = nullptr);
|
||||
~LtsAngleEdit();
|
||||
|
||||
enum class AngleUnitType : unsigned int
|
||||
{
|
||||
Deg = 0,
|
||||
Mil = 1,
|
||||
Rad = 2
|
||||
};
|
||||
Q_ENUM(AngleUnitType)
|
||||
enum class AngleUnitType : unsigned int { Deg = 0, Mil = 1, Rad = 2 };
|
||||
Q_ENUM(AngleUnitType)
|
||||
|
||||
enum LimTuple : int
|
||||
{
|
||||
AngleMin,
|
||||
AngleMax,
|
||||
DecimalPlace,
|
||||
SingleStep
|
||||
};
|
||||
enum LimTuple : int { AngleMin, AngleMax, DecimalPlace, SingleStep };
|
||||
|
||||
const QString spinBoxName = QStringLiteral("sboxAngleValue");
|
||||
QString toString(AngleUnitType t);
|
||||
void setAngleUnit(const AngleUnitType &type);
|
||||
void setValue(const double value, unsigned int dboxIndex=0);
|
||||
void setValue(const double value, AngleUnitType valueUnit);
|
||||
void setValue(const double value, AngleUnitType valueUnit, unsigned int dboxIndex);
|
||||
const QString spinBoxName = QStringLiteral("sboxAngleValue");
|
||||
QString toString(AngleUnitType t);
|
||||
void setAngleUnit(const AngleUnitType& type);
|
||||
void setValue(const double value, unsigned int dboxIndex = 0);
|
||||
void setValue(const double value, AngleUnitType valueUnit);
|
||||
void setValue(const double value, AngleUnitType valueUnit, unsigned int dboxIndex);
|
||||
|
||||
void hideUnits(const QVector<AngleUnitType> &list);
|
||||
void showUnits(const QVector<AngleUnitType> &list);
|
||||
LtsAngleEdit::AngleUnitType getAngleCurrentUnit() const;
|
||||
void initAngleEditWidget(const unsigned int sboxCount);
|
||||
double getAngle(unsigned int sboxIndex = 0) const;
|
||||
double getAngleConverted(const double angle, LtsAngleEdit::AngleUnitType newAngleUnit, LtsAngleEdit::AngleUnitType oldAngleUnit);
|
||||
void hideUnits(const QVector<AngleUnitType>& list);
|
||||
void showUnits(const QVector<AngleUnitType>& list);
|
||||
LtsAngleEdit::AngleUnitType getAngleCurrentUnit() const;
|
||||
void initAngleEditWidget(const unsigned int sboxCount);
|
||||
double getAngle(unsigned int sboxIndex = 0) const;
|
||||
double getAngleConverted(const double angle, LtsAngleEdit::AngleUnitType newAngleUnit,
|
||||
LtsAngleEdit::AngleUnitType oldAngleUnit);
|
||||
|
||||
void setEnable(int sbIndex, bool enabled);
|
||||
void showSpinbox(int sbIndex, bool visible);
|
||||
void setEnable(int sbIndex, bool enabled);
|
||||
void showSpinbox(int sbIndex, bool visible);
|
||||
|
||||
protected:
|
||||
void setCboxUnit();
|
||||
protected:
|
||||
void setCboxUnit();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onCBoxAngleUnitChanged();
|
||||
private:
|
||||
Ui_LtsAngleEdit *m_ui;
|
||||
QMap<int, QSharedPointer<QDoubleSpinBox>> m_sBoxMap;
|
||||
QMap<AngleUnitType, std::tuple<int,int,int,int>> m_dboxLimitMap;
|
||||
AngleUnitType m_currAngleUnit;
|
||||
QSet<int> m_hiddenUnits;
|
||||
private Q_SLOTS:
|
||||
void onCBoxAngleUnitChanged();
|
||||
|
||||
private:
|
||||
Ui_LtsAngleEdit* m_ui;
|
||||
QMap<int, QSharedPointer<QDoubleSpinBox>> m_sBoxMap;
|
||||
QMap<AngleUnitType, std::tuple<int, int, int, int>> m_dboxLimitMap;
|
||||
AngleUnitType m_currAngleUnit;
|
||||
QSet<int> m_hiddenUnits;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+20
-27
@@ -1,13 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QPixmap;
|
||||
class QEvent;
|
||||
@@ -15,38 +12,34 @@ class QEvent;
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsBackgroundWidget : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsBackgroundWidget(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit LtsBackgroundWidget(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void closeEvent(QCloseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
bool event(QEvent *e) override;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
void closeEvent(QCloseEvent* e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
bool event(QEvent* e) override;
|
||||
|
||||
private:
|
||||
void setBackground();
|
||||
void setUltraWide(bool set = true);
|
||||
private:
|
||||
void setBackground();
|
||||
void setUltraWide(bool set = true);
|
||||
|
||||
signals:
|
||||
|
||||
signals:
|
||||
|
||||
void signalOperatorAction();
|
||||
void signalOperatorAction();
|
||||
|
||||
public slots:
|
||||
|
||||
public slots:
|
||||
|
||||
void showFullScreen();
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
bool m_isUltraWide;
|
||||
void showFullScreen();
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
bool m_isUltraWide;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+155
-197
@@ -1,270 +1,228 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <LtsUtilsCore/lts_translatable_identifier.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QString>
|
||||
#include <QAbstractItemView>
|
||||
#include <QIcon>
|
||||
#include <QScrollArea>
|
||||
#include <QScroller>
|
||||
#include <QAbstractItemView>
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsDialog;
|
||||
|
||||
inline QString readableDuration(qint64 msecs, bool foldDays = true)
|
||||
{
|
||||
if (msecs == 0)
|
||||
return QObject::tr("---");
|
||||
if (msecs == 0)
|
||||
return QObject::tr("---");
|
||||
|
||||
|
||||
if (msecs % 1000 != 0 && msecs < 1000 * 60)
|
||||
return QObject::tr("%1 seconds").arg(QLocale().toString(msecs / 1000.0, 'f', 3));
|
||||
if (msecs % 1000 != 0 && msecs < 1000 * 60)
|
||||
return QObject::tr("%1 seconds").arg(QLocale().toString(msecs / 1000.0, 'f', 3));
|
||||
|
||||
qint64 secs = msecs / 1000;
|
||||
qint64 mins = secs / 60;
|
||||
qint64 hours = mins / 60;
|
||||
qint64 days = hours / 24;
|
||||
qint64 secs = msecs / 1000;
|
||||
qint64 mins = secs / 60;
|
||||
qint64 hours = mins / 60;
|
||||
qint64 days = hours / 24;
|
||||
|
||||
if (foldDays)
|
||||
days = 0;
|
||||
else
|
||||
hours = hours % 24;
|
||||
if (foldDays)
|
||||
days = 0;
|
||||
else
|
||||
hours = hours % 24;
|
||||
|
||||
mins = mins % 60;
|
||||
secs = secs % 60;
|
||||
mins = mins % 60;
|
||||
secs = secs % 60;
|
||||
|
||||
|
||||
if (!secs && !mins && !hours)
|
||||
return QObject::tr("%n day(s)", "", days);
|
||||
if (!secs && !mins && !days)
|
||||
return QObject::tr("%n hour(s)", "", hours);
|
||||
if (!secs && !hours && !days)
|
||||
return QObject::tr("%n minute(s)", "", mins);
|
||||
if (!mins && !hours && !days)
|
||||
return QObject::tr("%n second(s)", "", secs);
|
||||
if (!secs && !mins && !hours)
|
||||
return QObject::tr("%n day(s)", "", days);
|
||||
if (!secs && !mins && !days)
|
||||
return QObject::tr("%n hour(s)", "", hours);
|
||||
if (!secs && !hours && !days)
|
||||
return QObject::tr("%n minute(s)", "", mins);
|
||||
if (!mins && !hours && !days)
|
||||
return QObject::tr("%n second(s)", "", secs);
|
||||
|
||||
QString strSecs = QObject::tr("%1s").arg(secs, 2, 10, QLatin1Char('0'));
|
||||
QString strMins = QObject::tr("%1m").arg(mins, 2, 10, QLatin1Char('0'));
|
||||
QString strHours = QObject::tr("%1h").arg(hours, 2, 10, QLatin1Char('0'));
|
||||
QString strDays = QObject::tr("%1d").arg(days);
|
||||
QString strSecs = QObject::tr("%1s").arg(secs, 2, 10, QLatin1Char('0'));
|
||||
QString strMins = QObject::tr("%1m").arg(mins, 2, 10, QLatin1Char('0'));
|
||||
QString strHours = QObject::tr("%1h").arg(hours, 2, 10, QLatin1Char('0'));
|
||||
QString strDays = QObject::tr("%1d").arg(days);
|
||||
|
||||
QString retVal;
|
||||
if (days)
|
||||
retVal += strDays + QLatin1Char(' ');
|
||||
if (days || hours)
|
||||
retVal.append(strHours);
|
||||
if (mins || hours || days)
|
||||
retVal.append(strMins);
|
||||
if (secs)
|
||||
retVal.append(strSecs);
|
||||
QString retVal;
|
||||
if (days)
|
||||
retVal += strDays + QLatin1Char(' ');
|
||||
if (days || hours)
|
||||
retVal.append(strHours);
|
||||
if (mins || hours || days)
|
||||
retVal.append(strMins);
|
||||
if (secs)
|
||||
retVal.append(strSecs);
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline void addTouchScroll(QWidget *widget)
|
||||
inline void addTouchScroll(QWidget* widget)
|
||||
{
|
||||
if (!widget)
|
||||
return;
|
||||
widget->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
if (!widget)
|
||||
return;
|
||||
widget->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
|
||||
{
|
||||
QScrollArea *sca = qobject_cast<QScrollArea *>(widget);
|
||||
if (sca)
|
||||
{
|
||||
QScroller::grabGesture(sca->viewport(), QScroller::LeftMouseButtonGesture);
|
||||
return;
|
||||
QScrollArea* sca = qobject_cast<QScrollArea*>(widget);
|
||||
if (sca)
|
||||
{
|
||||
QScroller::grabGesture(sca->viewport(), QScroller::LeftMouseButtonGesture);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QAbstractItemView *aiv = qobject_cast<QAbstractItemView *>(widget);
|
||||
if (aiv)
|
||||
{
|
||||
QScroller::grabGesture(aiv->viewport(), QScroller::LeftMouseButtonGesture);
|
||||
aiv->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
aiv->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
return;
|
||||
QAbstractItemView* aiv = qobject_cast<QAbstractItemView*>(widget);
|
||||
if (aiv)
|
||||
{
|
||||
QScroller::grabGesture(aiv->viewport(), QScroller::LeftMouseButtonGesture);
|
||||
aiv->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
aiv->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class ButtonSize
|
||||
{
|
||||
eDefault = 40,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum class ButtonSize {
|
||||
eDefault = 40,
|
||||
|
||||
};
|
||||
|
||||
enum class ButtonStyle { eAll = 1, eTextOnly, eIconOnly, eTextNextToIcon };
|
||||
|
||||
enum class ButtonStyle
|
||||
{
|
||||
eAll = 1,
|
||||
eTextOnly,
|
||||
eIconOnly,
|
||||
eTextNextToIcon
|
||||
enum class LayoutArea {
|
||||
eUnknown,
|
||||
eInfoTab,
|
||||
eDialogTab,
|
||||
eSpecialTab,
|
||||
eMainTab,
|
||||
};
|
||||
|
||||
enum class LayoutArea
|
||||
{
|
||||
eUnknown,
|
||||
eInfoTab,
|
||||
eDialogTab,
|
||||
eSpecialTab,
|
||||
eMainTab,
|
||||
enum class ExercisePart {
|
||||
ePlanning,
|
||||
eExecution,
|
||||
eAfterAction,
|
||||
eSpecial,
|
||||
};
|
||||
|
||||
enum class ExercisePart
|
||||
{
|
||||
ePlanning,
|
||||
eExecution,
|
||||
eAfterAction,
|
||||
eSpecial,
|
||||
};
|
||||
|
||||
|
||||
namespace ExerciseState
|
||||
{
|
||||
enum State
|
||||
{
|
||||
|
||||
eUnknown = 0,
|
||||
eCreated = 1 << 0,
|
||||
eStarted = 1 << 1,
|
||||
ePaused = 1 << 2,
|
||||
eStopped = 1 << 4,
|
||||
enum State {
|
||||
|
||||
eUnknown = 0,
|
||||
eCreated = 1 << 0,
|
||||
eStarted = 1 << 1,
|
||||
ePaused = 1 << 2,
|
||||
eStopped = 1 << 4,
|
||||
eTerminated = 1 << 5,
|
||||
|
||||
eAll = eCreated | eStarted | ePaused | eStopped | eTerminated
|
||||
};
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<State>)
|
||||
}
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<State>)
|
||||
} // namespace ExerciseState
|
||||
|
||||
typedef ExerciseState::State ExcState;
|
||||
typedef QFlags<ExcState> ExerciseStates;
|
||||
typedef ExerciseState::State ExcState;
|
||||
typedef QFlags<ExcState> ExerciseStates;
|
||||
|
||||
enum class CreateInstantType
|
||||
{
|
||||
DontCreateInstant,
|
||||
CreateInstantAndAddAction,
|
||||
CreateInstantAndDiscardAction,
|
||||
enum class CreateInstantType {
|
||||
DontCreateInstant,
|
||||
CreateInstantAndAddAction,
|
||||
CreateInstantAndDiscardAction,
|
||||
};
|
||||
|
||||
struct PluginData
|
||||
{
|
||||
|
||||
using createWidgetFuncPtr = std::function<LtsDialog*(QWidget *)>;
|
||||
using directFuncPtr = std::function<void(const LtsWidgets::PluginData &)>;
|
||||
|
||||
createWidgetFuncPtr createWidgetFunc = nullptr;
|
||||
directFuncPtr directFunc = nullptr;
|
||||
QStringList iconPaths;
|
||||
QIcon menuIcon;
|
||||
QString tooltip;
|
||||
qulonglong dropHandlerKey = 0;
|
||||
QString menuText;
|
||||
QString menuGroup;
|
||||
LtsUtils::LtsTranslatableIdentifier translatableMenuGroup;
|
||||
QString identifier;
|
||||
bool closable = true;
|
||||
LayoutArea layoutArea = LayoutArea::eDialogTab;
|
||||
int operatorRight = 0;
|
||||
CreateInstantType createInstant = CreateInstantType::DontCreateInstant;
|
||||
bool visibleInMenu = true;
|
||||
ExercisePart exercisePart = ExercisePart::eSpecial;
|
||||
ExerciseStates exerciseStates = ExerciseState::eAll;
|
||||
using createWidgetFuncPtr = std::function<LtsDialog*(QWidget*)>;
|
||||
using directFuncPtr = std::function<void(const LtsWidgets::PluginData&)>;
|
||||
|
||||
PluginData() = default;
|
||||
PluginData(const QString &_menuGroup,
|
||||
const QString &_menuText,
|
||||
const QString &_identifier,
|
||||
const createWidgetFuncPtr &_cwfp,
|
||||
int _operatorRight,
|
||||
ExercisePart _exercisePart = ExercisePart::eSpecial,
|
||||
ExerciseStates _exerciseStates = ExerciseState::eAll)
|
||||
: PluginData(_menuGroup, _menuText, _identifier, QIcon(), _cwfp, _operatorRight, _exercisePart, _exerciseStates)
|
||||
{}
|
||||
createWidgetFuncPtr createWidgetFunc = nullptr;
|
||||
directFuncPtr directFunc = nullptr;
|
||||
QStringList iconPaths;
|
||||
QIcon menuIcon;
|
||||
QString tooltip;
|
||||
qulonglong dropHandlerKey = 0;
|
||||
QString menuText;
|
||||
QString menuGroup;
|
||||
LtsUtils::LtsTranslatableIdentifier translatableMenuGroup;
|
||||
QString identifier;
|
||||
bool closable = true;
|
||||
LayoutArea layoutArea = LayoutArea::eDialogTab;
|
||||
int operatorRight = 0;
|
||||
CreateInstantType createInstant = CreateInstantType::DontCreateInstant;
|
||||
bool visibleInMenu = true;
|
||||
ExercisePart exercisePart = ExercisePart::eSpecial;
|
||||
ExerciseStates exerciseStates = ExerciseState::eAll;
|
||||
|
||||
PluginData(const QString &_menuGroup,
|
||||
const QString &_menuText,
|
||||
const QString &_identifier,
|
||||
const QIcon &_icon,
|
||||
const createWidgetFuncPtr &_cwfp,
|
||||
int _operatorRight,
|
||||
ExercisePart _exercisePart = ExercisePart::eSpecial,
|
||||
ExerciseStates _exerciseStates = ExerciseState::eAll)
|
||||
: createWidgetFunc(_cwfp)
|
||||
, menuIcon(_icon)
|
||||
, menuText(_menuText)
|
||||
, menuGroup(_menuGroup)
|
||||
, identifier(_identifier)
|
||||
, operatorRight(_operatorRight)
|
||||
, exercisePart(_exercisePart)
|
||||
, exerciseStates(_exerciseStates)
|
||||
{
|
||||
}
|
||||
PluginData() = default;
|
||||
|
||||
static PluginData createGroup(const QString &menuGroup,
|
||||
const QString &menuText,
|
||||
const QString &identifier,
|
||||
int operatorRight)
|
||||
{
|
||||
return PluginData(menuGroup, menuText, identifier, nullptr, operatorRight, ExercisePart::eSpecial);
|
||||
}
|
||||
bool isValid() const { return createWidgetFunc != nullptr; }
|
||||
PluginData(const QString& _menuGroup, const QString& _menuText, const QString& _identifier,
|
||||
const createWidgetFuncPtr& _cwfp, int _operatorRight,
|
||||
ExercisePart _exercisePart = ExercisePart::eSpecial,
|
||||
ExerciseStates _exerciseStates = ExerciseState::eAll)
|
||||
: PluginData(_menuGroup, _menuText, _identifier, QIcon(), _cwfp, _operatorRight, _exercisePart, _exerciseStates)
|
||||
{
|
||||
}
|
||||
|
||||
PluginData(const QString& _menuGroup, const QString& _menuText, const QString& _identifier, const QIcon& _icon,
|
||||
const createWidgetFuncPtr& _cwfp, int _operatorRight,
|
||||
ExercisePart _exercisePart = ExercisePart::eSpecial,
|
||||
ExerciseStates _exerciseStates = ExerciseState::eAll)
|
||||
: createWidgetFunc(_cwfp), menuIcon(_icon), menuText(_menuText), menuGroup(_menuGroup), identifier(_identifier),
|
||||
operatorRight(_operatorRight), exercisePart(_exercisePart), exerciseStates(_exerciseStates)
|
||||
{
|
||||
}
|
||||
|
||||
static PluginData createGroup(const QString& menuGroup, const QString& menuText, const QString& identifier,
|
||||
int operatorRight)
|
||||
{
|
||||
return PluginData(menuGroup, menuText, identifier, nullptr, operatorRight, ExercisePart::eSpecial);
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return createWidgetFunc != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT Designer
|
||||
{
|
||||
Q_GADGET
|
||||
public:
|
||||
enum ButtonSize
|
||||
{
|
||||
eDefault = static_cast<int>(LtsWidgets::ButtonSize::eDefault),
|
||||
Q_GADGET
|
||||
public:
|
||||
enum ButtonSize {
|
||||
eDefault = static_cast<int>(LtsWidgets::ButtonSize::eDefault),
|
||||
|
||||
};
|
||||
Q_ENUM(ButtonSize)
|
||||
|
||||
enum ButtonStyle {
|
||||
eAll = static_cast<int>(LtsWidgets::ButtonStyle::eAll),
|
||||
eTextOnly = static_cast<int>(LtsWidgets::ButtonStyle::eTextOnly),
|
||||
eIconOnly = static_cast<int>(LtsWidgets::ButtonStyle::eIconOnly),
|
||||
eTextNextToIcon = static_cast<int>(LtsWidgets::ButtonStyle::eTextNextToIcon)
|
||||
};
|
||||
Q_ENUM(ButtonStyle)
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
Q_ENUM(ButtonSize)
|
||||
enum ButtonStyle
|
||||
{
|
||||
eAll = static_cast<int>(LtsWidgets::ButtonStyle::eAll),
|
||||
eTextOnly = static_cast<int>(LtsWidgets::ButtonStyle::eTextOnly),
|
||||
eIconOnly = static_cast<int>(LtsWidgets::ButtonStyle::eIconOnly),
|
||||
eTextNextToIcon = static_cast<int>(LtsWidgets::ButtonStyle::eTextNextToIcon)
|
||||
};
|
||||
Q_ENUM(ButtonStyle)
|
||||
enum LayoutArea
|
||||
{
|
||||
eUnknownArea = static_cast<int>(LtsWidgets::LayoutArea::eUnknown),
|
||||
eInfoTab = static_cast<int>(LtsWidgets::LayoutArea::eInfoTab),
|
||||
eDialogTab = static_cast<int>(LtsWidgets::LayoutArea::eDialogTab),
|
||||
eSpecialTab = static_cast<int>(LtsWidgets::LayoutArea::eSpecialTab),
|
||||
eMainTab = static_cast<int>(LtsWidgets::LayoutArea::eMainTab)
|
||||
};
|
||||
Q_ENUM(LayoutArea)
|
||||
enum LayoutArea {
|
||||
eUnknownArea = static_cast<int>(LtsWidgets::LayoutArea::eUnknown),
|
||||
eInfoTab = static_cast<int>(LtsWidgets::LayoutArea::eInfoTab),
|
||||
eDialogTab = static_cast<int>(LtsWidgets::LayoutArea::eDialogTab),
|
||||
eSpecialTab = static_cast<int>(LtsWidgets::LayoutArea::eSpecialTab),
|
||||
eMainTab = static_cast<int>(LtsWidgets::LayoutArea::eMainTab)
|
||||
};
|
||||
Q_ENUM(LayoutArea)
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Q_DECLARE_METATYPE(LtsWidgets::Designer::ButtonSize)
|
||||
Q_DECLARE_METATYPE(LtsWidgets::Designer::ButtonStyle)
|
||||
Q_DECLARE_METATYPE(LtsWidgets::Designer::LayoutArea)
|
||||
|
||||
Executable → Regular
+246
-298
@@ -1,19 +1,16 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
#include "lts_notification_box.h"
|
||||
#include "ltswidgets_export.h"
|
||||
#include "qevent.h"
|
||||
|
||||
#include <memory>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class QButtonGroup;
|
||||
class QPropertyAnimation;
|
||||
@@ -31,7 +28,10 @@ namespace IDL
|
||||
enum class PartitionType;
|
||||
}
|
||||
|
||||
namespace LtsUtils { class Promise; }
|
||||
namespace LtsUtils
|
||||
{
|
||||
class Promise;
|
||||
}
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
@@ -43,305 +43,253 @@ class LtsToolBox;
|
||||
|
||||
struct ExerciseData
|
||||
{
|
||||
QString exName;
|
||||
QString exDescription;
|
||||
int phId = -1;
|
||||
QString phName;
|
||||
QString phDescription;
|
||||
QString exStateString;
|
||||
ExcState exState = ExerciseState::eUnknown;
|
||||
QColor exStateCol;
|
||||
QString partitionType;
|
||||
QString exName;
|
||||
QString exDescription;
|
||||
int phId = -1;
|
||||
QString phName;
|
||||
QString phDescription;
|
||||
QString exStateString;
|
||||
ExcState exState = ExerciseState::eUnknown;
|
||||
QColor exStateCol;
|
||||
QString partitionType;
|
||||
|
||||
bool operator==(const ExerciseData &o) const
|
||||
{
|
||||
return exName == o.exName &&
|
||||
exDescription == o.exDescription &&
|
||||
phId == o.phId &&
|
||||
phName == o.phName &&
|
||||
phDescription == o.phDescription &&
|
||||
exStateString == o.exStateString &&
|
||||
exState == o.exState &&
|
||||
exStateCol == o.exStateCol &&
|
||||
partitionType == o.partitionType;
|
||||
}
|
||||
bool operator!=(const ExerciseData &o) const
|
||||
{
|
||||
return !operator ==(o);
|
||||
}
|
||||
bool operator==(const ExerciseData& o) const
|
||||
{
|
||||
return exName == o.exName && exDescription == o.exDescription && phId == o.phId && phName == o.phName &&
|
||||
phDescription == o.phDescription && exStateString == o.exStateString && exState == o.exState &&
|
||||
exStateCol == o.exStateCol && partitionType == o.partitionType;
|
||||
}
|
||||
|
||||
bool operator!=(const ExerciseData& o) const
|
||||
{
|
||||
return !operator==(o);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsBaseLayoutWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit LtsBaseLayoutWidget(QWidget *parent = nullptr, bool splitMenu = true);
|
||||
~LtsBaseLayoutWidget();
|
||||
|
||||
|
||||
|
||||
void hideVisibleLayouts();
|
||||
|
||||
|
||||
|
||||
void resetLayoutVisibility();
|
||||
|
||||
|
||||
|
||||
void setMenuVisible(bool visible);
|
||||
|
||||
|
||||
|
||||
bool isMenuVisible() const;
|
||||
|
||||
bool isTopBarVisible() const;
|
||||
void setTopBarVisible(bool visible);
|
||||
|
||||
|
||||
|
||||
bool isMenuCollapsed() const;
|
||||
|
||||
|
||||
|
||||
void collapseMenu(bool collapse = true);
|
||||
|
||||
|
||||
|
||||
void setSessionInfo(const int domainId, const IDL::PartitionType &partitionType, const int partitionId, const QString &workspaceId);
|
||||
|
||||
|
||||
|
||||
LtsDragIcon *addMenuAction(const PluginData &plData, bool isFirstRun = false);
|
||||
|
||||
|
||||
|
||||
bool removeMenuAction(const PluginData &plData);
|
||||
|
||||
|
||||
|
||||
bool removeMenuAction(LtsDragIcon *icon);
|
||||
|
||||
bool removeMenuAction(const QString &byIdentifier);
|
||||
|
||||
|
||||
|
||||
void clearMenuActions();
|
||||
|
||||
void setAppName(const QString &appName);
|
||||
bool isDialogFocused(const LtsDialog *dialog) const;
|
||||
|
||||
|
||||
|
||||
void setCustomText(const QString &text);
|
||||
const QString customText() const;
|
||||
|
||||
|
||||
|
||||
LtsTabWidget *getTabFromLayoutArea(LayoutArea area) const;
|
||||
|
||||
|
||||
|
||||
LtsDialog *getWidget(const QString &menuGroup, const QString &identifier, LayoutArea area = LayoutArea::eUnknown);
|
||||
|
||||
|
||||
|
||||
QWidget *getMenu() const;
|
||||
|
||||
|
||||
|
||||
LtsToolBarArea *getToolbar() const;
|
||||
|
||||
|
||||
|
||||
void setOperatorName(const QString &operatorName, bool showTerminalButton);
|
||||
|
||||
|
||||
|
||||
void setProfilePicture(const QPixmap &profilePicture);
|
||||
|
||||
|
||||
|
||||
void setExerciseData(const ExerciseData &data);
|
||||
|
||||
|
||||
|
||||
void initilizationFinished();
|
||||
|
||||
|
||||
|
||||
void addNotification(QToolButton *noti);
|
||||
|
||||
|
||||
|
||||
bool isWidgetsHidden() const;
|
||||
|
||||
bool notificationExists(const QString &identifier) const;
|
||||
const QMap<LtsDragIcon *, PluginData> &mapButtons() const { return m_mapButtons; }
|
||||
void setToolBarActions(const QStringList &actions);
|
||||
QStringList toolBarActions() const;
|
||||
void setFunctionKeys(const QMap<int, QString> &actions);
|
||||
QMap<int, QString> functionKeys() const;
|
||||
void setWorkspaceId(const QString &workspaceId) { m_workspaceId = workspaceId; }
|
||||
|
||||
|
||||
|
||||
void showMessage(const QString &title, const QString &text, LtsNotificationBox::MessageType type = LtsNotificationBox::MessageType::Info, const std::function<void(const QString &link)> &clickedLinkCallback = nullptr, bool closeOnLinkClicked = true, const QString &identifier = {});
|
||||
bool messageIdentifierExists(const QString &identifier) const;
|
||||
|
||||
void executeAction(const QString &actionIdentifier);
|
||||
bool isSecondaryWidget() const { return m_isSecondaryWidget; }
|
||||
void setSecondaryWidget() { m_isSecondaryWidget = true; }
|
||||
|
||||
|
||||
|
||||
void removeQueuedMessage(const QString &messageIdentifier);
|
||||
|
||||
|
||||
public slots:
|
||||
bool slotClose();
|
||||
void slotLogout();
|
||||
|
||||
void slotScreenCountChanged(int count);
|
||||
|
||||
|
||||
|
||||
void onMenuEntryClicked();
|
||||
|
||||
void onHideAnimated();
|
||||
void onReShowAnimated();
|
||||
|
||||
|
||||
|
||||
bool addWidget(LtsWidgets::LtsDialog *dialog, const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area = LayoutArea::eUnknown, bool setClosable = true, bool focusNewTab = true);
|
||||
|
||||
|
||||
|
||||
bool addOrReplaceWidget(LtsDialog *dialog, const QString &menuGroup, const QString &identifier, LayoutArea area = LayoutArea::eUnknown, bool setClosable = true, bool focusNewTab = true );
|
||||
|
||||
bool focusTab(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area);
|
||||
|
||||
|
||||
|
||||
void executeCreateInstantFunctions(const LtsWidgets::PluginData &plData);
|
||||
|
||||
void setExerciseTime(qint64 mSecsSinceEpoch);
|
||||
bool haveUnsavedChanges();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool notifyUnsavedChanges();
|
||||
|
||||
|
||||
|
||||
void setIrreplaceableOnce() { m_irreplaceableOnce = true; }
|
||||
bool irreplaceableReset() { bool r = m_irreplaceableOnce; m_irreplaceableOnce = false; return r; }
|
||||
bool isIrreplaceable() const { return m_irreplaceableOnce; }
|
||||
|
||||
|
||||
|
||||
void showWidgets();
|
||||
|
||||
|
||||
|
||||
void hideWidgets();
|
||||
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
void slotOperatorMenuClicked();
|
||||
|
||||
void setCurrentTime();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
|
||||
|
||||
void signalClose();
|
||||
void signalLogout();
|
||||
void signalShowOperatorSettings();
|
||||
void signalRetranslateActions();
|
||||
void signalSwap();
|
||||
void signalStapleTopicLockHandler(LtsWidgets::LtsDialog *widget);
|
||||
void signalSuccessfullyPlaced();
|
||||
|
||||
|
||||
|
||||
void signalNotifyUnsavedChanges(bool &reject);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
|
||||
private:
|
||||
void addDebugMenu();
|
||||
void retranslate();
|
||||
void addTouchScroll(QWidget *widget);
|
||||
LtsDragIcon *createButton(const PluginData &plData);
|
||||
int getIndexOfTab(LtsTabWidget *tab);
|
||||
LtsToolBox *getToolBox(const ExercisePart &exercisePart) const;
|
||||
QPushButton *getExercisePartButton(const ExercisePart &exercisePart) const;
|
||||
void checkExercisePartButtonVisibility();
|
||||
void checkMenuGroup(const QString &menuGroup, const ExercisePart &exercisePart);
|
||||
bool isDialogFocused(const LtsDialog *dialog, const LayoutArea &layoutArea) const;
|
||||
bool isDialogFocused(const LtsDialog *dialog, const LtsTabWidget *tab) const;
|
||||
void applyExerciseStateRestricition();
|
||||
void executePluginData(const PluginData &plData);
|
||||
void showNextQueuedMessage();
|
||||
|
||||
|
||||
struct Message
|
||||
{
|
||||
public:
|
||||
QString title;
|
||||
QString text;
|
||||
LtsNotificationBox::MessageType type;
|
||||
std::function<void(const QString &link)> clickedLinkCallback;
|
||||
bool closeOnLinkClicked;
|
||||
QString identifier;
|
||||
};
|
||||
explicit LtsBaseLayoutWidget(QWidget* parent = nullptr, bool splitMenu = true);
|
||||
~LtsBaseLayoutWidget();
|
||||
|
||||
ExerciseData m_exerciseData;
|
||||
QMap<LtsDragIcon *, PluginData> m_mapButtons;
|
||||
QList<int> m_mainSplitterSizes;
|
||||
QList<int> m_menuSplitterSizes;
|
||||
bool m_isHidden;
|
||||
QPropertyAnimation *m_currentAnimation{nullptr};
|
||||
Ui::LtsBaseLayoutWidget *m_ui{nullptr};
|
||||
IDL::PartitionType m_partitionType;
|
||||
int m_domainId;
|
||||
int m_partitionId;
|
||||
QString m_operatorName;
|
||||
bool m_firstShow;
|
||||
bool m_showTerminalButton;
|
||||
qint64 m_exerciseTime;
|
||||
QTimer *m_setCurrentTimeTimer{nullptr};
|
||||
bool m_irreplaceableOnce;
|
||||
QButtonGroup *m_bg{nullptr};
|
||||
QString m_workspaceId;
|
||||
int m_screenCount;
|
||||
bool m_menuCollapsed;
|
||||
QMap<QPointer<LtsWidgets::LtsTabWidget>, bool> m_oldLayoutVisibilityStates;
|
||||
LtsNotificationBox *m_notiBox{nullptr};
|
||||
QStringList m_notFoundYet;
|
||||
bool m_isSecondaryWidget { false };
|
||||
QVector<Message> m_currentMessage;
|
||||
QVector<Message> m_messageQueue;
|
||||
void hideVisibleLayouts();
|
||||
|
||||
void resetLayoutVisibility();
|
||||
|
||||
void setMenuVisible(bool visible);
|
||||
|
||||
bool isMenuVisible() const;
|
||||
|
||||
bool isTopBarVisible() const;
|
||||
void setTopBarVisible(bool visible);
|
||||
|
||||
bool isMenuCollapsed() const;
|
||||
|
||||
void collapseMenu(bool collapse = true);
|
||||
|
||||
void setSessionInfo(const int domainId, const IDL::PartitionType& partitionType, const int partitionId,
|
||||
const QString& workspaceId);
|
||||
|
||||
LtsDragIcon* addMenuAction(const PluginData& plData, bool isFirstRun = false);
|
||||
|
||||
bool removeMenuAction(const PluginData& plData);
|
||||
|
||||
bool removeMenuAction(LtsDragIcon* icon);
|
||||
|
||||
bool removeMenuAction(const QString& byIdentifier);
|
||||
|
||||
void clearMenuActions();
|
||||
|
||||
void setAppName(const QString& appName);
|
||||
bool isDialogFocused(const LtsDialog* dialog) const;
|
||||
|
||||
void setCustomText(const QString& text);
|
||||
const QString customText() const;
|
||||
|
||||
LtsTabWidget* getTabFromLayoutArea(LayoutArea area) const;
|
||||
|
||||
LtsDialog* getWidget(const QString& menuGroup, const QString& identifier, LayoutArea area = LayoutArea::eUnknown);
|
||||
|
||||
QWidget* getMenu() const;
|
||||
|
||||
LtsToolBarArea* getToolbar() const;
|
||||
|
||||
void setOperatorName(const QString& operatorName, bool showTerminalButton);
|
||||
|
||||
void setProfilePicture(const QPixmap& profilePicture);
|
||||
|
||||
void setExerciseData(const ExerciseData& data);
|
||||
|
||||
void initilizationFinished();
|
||||
|
||||
void addNotification(QToolButton* noti);
|
||||
|
||||
bool isWidgetsHidden() const;
|
||||
|
||||
bool notificationExists(const QString& identifier) const;
|
||||
|
||||
const QMap<LtsDragIcon*, PluginData>& mapButtons() const
|
||||
{
|
||||
return m_mapButtons;
|
||||
}
|
||||
|
||||
void setToolBarActions(const QStringList& actions);
|
||||
QStringList toolBarActions() const;
|
||||
void setFunctionKeys(const QMap<int, QString>& actions);
|
||||
QMap<int, QString> functionKeys() const;
|
||||
|
||||
void setWorkspaceId(const QString& workspaceId)
|
||||
{
|
||||
m_workspaceId = workspaceId;
|
||||
}
|
||||
|
||||
void showMessage(const QString& title, const QString& text,
|
||||
LtsNotificationBox::MessageType type = LtsNotificationBox::MessageType::Info,
|
||||
const std::function<void(const QString& link)>& clickedLinkCallback = nullptr,
|
||||
bool closeOnLinkClicked = true, const QString& identifier = {});
|
||||
bool messageIdentifierExists(const QString& identifier) const;
|
||||
|
||||
void executeAction(const QString& actionIdentifier);
|
||||
|
||||
bool isSecondaryWidget() const
|
||||
{
|
||||
return m_isSecondaryWidget;
|
||||
}
|
||||
|
||||
void setSecondaryWidget()
|
||||
{
|
||||
m_isSecondaryWidget = true;
|
||||
}
|
||||
|
||||
void removeQueuedMessage(const QString& messageIdentifier);
|
||||
|
||||
public slots:
|
||||
bool slotClose();
|
||||
void slotLogout();
|
||||
|
||||
void slotScreenCountChanged(int count);
|
||||
|
||||
void onMenuEntryClicked();
|
||||
|
||||
void onHideAnimated();
|
||||
void onReShowAnimated();
|
||||
|
||||
bool addWidget(LtsWidgets::LtsDialog* dialog, const QString& menuGroup, const QString& identifier,
|
||||
LtsWidgets::LayoutArea area = LayoutArea::eUnknown, bool setClosable = true,
|
||||
bool focusNewTab = true);
|
||||
|
||||
bool addOrReplaceWidget(LtsDialog* dialog, const QString& menuGroup, const QString& identifier,
|
||||
LayoutArea area = LayoutArea::eUnknown, bool setClosable = true, bool focusNewTab = true);
|
||||
|
||||
bool focusTab(const QString& menuGroup, const QString& identifier, LtsWidgets::LayoutArea area);
|
||||
|
||||
void executeCreateInstantFunctions(const LtsWidgets::PluginData& plData);
|
||||
|
||||
void setExerciseTime(qint64 mSecsSinceEpoch);
|
||||
bool haveUnsavedChanges();
|
||||
|
||||
bool notifyUnsavedChanges();
|
||||
|
||||
void setIrreplaceableOnce()
|
||||
{
|
||||
m_irreplaceableOnce = true;
|
||||
}
|
||||
|
||||
bool irreplaceableReset()
|
||||
{
|
||||
bool r = m_irreplaceableOnce;
|
||||
m_irreplaceableOnce = false;
|
||||
return r;
|
||||
}
|
||||
|
||||
bool isIrreplaceable() const
|
||||
{
|
||||
return m_irreplaceableOnce;
|
||||
}
|
||||
|
||||
void showWidgets();
|
||||
|
||||
void hideWidgets();
|
||||
|
||||
private slots:
|
||||
|
||||
void slotOperatorMenuClicked();
|
||||
|
||||
void setCurrentTime();
|
||||
|
||||
signals:
|
||||
|
||||
void signalClose();
|
||||
void signalLogout();
|
||||
void signalShowOperatorSettings();
|
||||
void signalRetranslateActions();
|
||||
void signalSwap();
|
||||
void signalStapleTopicLockHandler(LtsWidgets::LtsDialog* widget);
|
||||
void signalSuccessfullyPlaced();
|
||||
|
||||
void signalNotifyUnsavedChanges(bool& reject);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void changeEvent(QEvent* e) override;
|
||||
|
||||
private:
|
||||
void addDebugMenu();
|
||||
void retranslate();
|
||||
void addTouchScroll(QWidget* widget);
|
||||
LtsDragIcon* createButton(const PluginData& plData);
|
||||
int getIndexOfTab(LtsTabWidget* tab);
|
||||
LtsToolBox* getToolBox(const ExercisePart& exercisePart) const;
|
||||
QPushButton* getExercisePartButton(const ExercisePart& exercisePart) const;
|
||||
void checkExercisePartButtonVisibility();
|
||||
void checkMenuGroup(const QString& menuGroup, const ExercisePart& exercisePart);
|
||||
bool isDialogFocused(const LtsDialog* dialog, const LayoutArea& layoutArea) const;
|
||||
bool isDialogFocused(const LtsDialog* dialog, const LtsTabWidget* tab) const;
|
||||
void applyExerciseStateRestricition();
|
||||
void executePluginData(const PluginData& plData);
|
||||
void showNextQueuedMessage();
|
||||
|
||||
struct Message
|
||||
{
|
||||
public:
|
||||
QString title;
|
||||
QString text;
|
||||
LtsNotificationBox::MessageType type;
|
||||
std::function<void(const QString& link)> clickedLinkCallback;
|
||||
bool closeOnLinkClicked;
|
||||
QString identifier;
|
||||
};
|
||||
|
||||
ExerciseData m_exerciseData;
|
||||
QMap<LtsDragIcon*, PluginData> m_mapButtons;
|
||||
QList<int> m_mainSplitterSizes;
|
||||
QList<int> m_menuSplitterSizes;
|
||||
bool m_isHidden;
|
||||
QPropertyAnimation* m_currentAnimation{nullptr};
|
||||
Ui::LtsBaseLayoutWidget* m_ui{nullptr};
|
||||
IDL::PartitionType m_partitionType;
|
||||
int m_domainId;
|
||||
int m_partitionId;
|
||||
QString m_operatorName;
|
||||
bool m_firstShow;
|
||||
bool m_showTerminalButton;
|
||||
qint64 m_exerciseTime;
|
||||
QTimer* m_setCurrentTimeTimer{nullptr};
|
||||
bool m_irreplaceableOnce;
|
||||
QButtonGroup* m_bg{nullptr};
|
||||
QString m_workspaceId;
|
||||
int m_screenCount;
|
||||
bool m_menuCollapsed;
|
||||
QMap<QPointer<LtsWidgets::LtsTabWidget>, bool> m_oldLayoutVisibilityStates;
|
||||
LtsNotificationBox* m_notiBox{nullptr};
|
||||
QStringList m_notFoundYet;
|
||||
bool m_isSecondaryWidget{false};
|
||||
QVector<Message> m_currentMessage;
|
||||
QVector<Message> m_messageQueue;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+72
-76
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_bitfield_widget.h"
|
||||
|
||||
#include <QPainter>
|
||||
@@ -8,122 +7,119 @@
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsBitfieldWidget::LtsBitfieldWidget(QWidget *parent, quint8 value)
|
||||
: QWidget(parent)
|
||||
, m_value(value)
|
||||
LtsBitfieldWidget::LtsBitfieldWidget(QWidget* parent, quint8 value) : QWidget(parent), m_value(value)
|
||||
{
|
||||
setObjectName(QString::fromUtf8("LtsBitfieldWidget"));
|
||||
setObjectName(QString::fromUtf8("LtsBitfieldWidget"));
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::paintEvent(QPaintEvent *pe)
|
||||
void LtsBitfieldWidget::paintEvent(QPaintEvent* pe)
|
||||
{
|
||||
QWidget::paintEvent(pe);
|
||||
QWidget::paintEvent(pe);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
painter.setPen(Qt::SolidLine);
|
||||
|
||||
if (m_hasCaption)
|
||||
{
|
||||
QFont font = painter.font();
|
||||
font.setPointSizeF( (height()/2.0 > width()/8.0) ? width()/8.0 : height()/2.0 );
|
||||
painter.setFont(font);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
QRectF bitGraphic;
|
||||
|
||||
bitGraphic.setLeft(width() / 8.0 * i);
|
||||
bitGraphic.setWidth((width() / 8.0) - 1);
|
||||
bitGraphic.setHeight(height() - 1);
|
||||
|
||||
bool bitVal = (m_value & (1 << (7 - i))) > 0;
|
||||
|
||||
painter.fillRect(bitGraphic, QBrush(bitVal ? m_onColor : m_offColor, Qt::SolidPattern));
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
painter.setPen(Qt::SolidLine);
|
||||
|
||||
if (m_hasCaption)
|
||||
{
|
||||
painter.setPen(bitVal ? m_offColor : m_onColor);
|
||||
painter.drawText(bitGraphic, Qt::AlignCenter, bitVal ? QStringLiteral("1") : QStringLiteral("0"));
|
||||
QFont font = painter.font();
|
||||
font.setPointSizeF((height() / 2.0 > width() / 8.0) ? width() / 8.0 : height() / 2.0);
|
||||
painter.setFont(font);
|
||||
}
|
||||
|
||||
painter.setPen(Qt::gray);
|
||||
painter.drawRect(bitGraphic);
|
||||
}
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
QRectF bitGraphic;
|
||||
|
||||
painter.end();
|
||||
bitGraphic.setLeft(width() / 8.0 * i);
|
||||
bitGraphic.setWidth((width() / 8.0) - 1);
|
||||
bitGraphic.setHeight(height() - 1);
|
||||
|
||||
bool bitVal = (m_value & (1 << (7 - i))) > 0;
|
||||
|
||||
painter.fillRect(bitGraphic, QBrush(bitVal ? m_onColor : m_offColor, Qt::SolidPattern));
|
||||
|
||||
if (m_hasCaption)
|
||||
{
|
||||
painter.setPen(bitVal ? m_offColor : m_onColor);
|
||||
painter.drawText(bitGraphic, Qt::AlignCenter, bitVal ? QStringLiteral("1") : QStringLiteral("0"));
|
||||
}
|
||||
|
||||
painter.setPen(Qt::gray);
|
||||
painter.drawRect(bitGraphic);
|
||||
}
|
||||
|
||||
painter.end();
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::setHasCaption(bool hasCaption)
|
||||
{
|
||||
if (m_hasCaption == hasCaption)
|
||||
return;
|
||||
if (m_hasCaption == hasCaption)
|
||||
return;
|
||||
|
||||
m_hasCaption = hasCaption;
|
||||
repaint();
|
||||
m_hasCaption = hasCaption;
|
||||
repaint();
|
||||
|
||||
emit hasCaptionChanged(hasCaption);
|
||||
emit hasCaptionChanged(hasCaption);
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::setOnColor(const QColor &onColor)
|
||||
void LtsBitfieldWidget::setOnColor(const QColor& onColor)
|
||||
{
|
||||
if (m_onColor == onColor)
|
||||
return;
|
||||
if (m_onColor == onColor)
|
||||
return;
|
||||
|
||||
m_onColor = onColor;
|
||||
repaint();
|
||||
m_onColor = onColor;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::setOffColor(const QColor &offColor)
|
||||
void LtsBitfieldWidget::setOffColor(const QColor& offColor)
|
||||
{
|
||||
if (m_offColor == offColor)
|
||||
return;
|
||||
if (m_offColor == offColor)
|
||||
return;
|
||||
|
||||
m_offColor = offColor;
|
||||
repaint();
|
||||
m_offColor = offColor;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::mousePressEvent(QMouseEvent *event)
|
||||
void LtsBitfieldWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!m_isEditable)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
if (event->pos().x() > width()/8 * i &&
|
||||
event->pos().x() < width()/8 * (i + 1))
|
||||
if (!m_isEditable)
|
||||
{
|
||||
m_value ^= (1 << (7 - i));
|
||||
emit valueChanged(m_value);
|
||||
break;
|
||||
QWidget::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
if (event->pos().x() > width() / 8 * i && event->pos().x() < width() / 8 * (i + 1))
|
||||
{
|
||||
m_value ^= (1 << (7 - i));
|
||||
emit valueChanged(m_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::setEditable(bool editable)
|
||||
{
|
||||
if (m_isEditable == editable)
|
||||
return;
|
||||
if (m_isEditable == editable)
|
||||
return;
|
||||
|
||||
m_isEditable = editable;
|
||||
m_isEditable = editable;
|
||||
|
||||
emit isEditableChanged(m_isEditable);
|
||||
emit isEditableChanged(m_isEditable);
|
||||
}
|
||||
|
||||
void LtsBitfieldWidget::setValue(quint8 value)
|
||||
{
|
||||
if (m_value == value)
|
||||
return;
|
||||
if (m_value == value)
|
||||
return;
|
||||
|
||||
m_value = value;
|
||||
repaint();
|
||||
m_value = value;
|
||||
repaint();
|
||||
|
||||
emit valueChanged(m_value);
|
||||
emit valueChanged(m_value);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+52
-64
@@ -1,96 +1,84 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsBitfieldWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(quint8 value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(bool isEditable READ isEditable WRITE setEditable NOTIFY isEditableChanged)
|
||||
Q_PROPERTY(bool hasCaption READ hasCaption WRITE setHasCaption NOTIFY hasCaptionChanged)
|
||||
Q_PROPERTY(QColor onColor READ onColor WRITE setOnColor)
|
||||
Q_PROPERTY(QColor offColor READ offColor WRITE setOffColor)
|
||||
Q_PROPERTY(quint8 value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(bool isEditable READ isEditable WRITE setEditable NOTIFY isEditableChanged)
|
||||
Q_PROPERTY(bool hasCaption READ hasCaption WRITE setHasCaption NOTIFY hasCaptionChanged)
|
||||
Q_PROPERTY(QColor onColor READ onColor WRITE setOnColor)
|
||||
Q_PROPERTY(QColor offColor READ offColor WRITE setOffColor)
|
||||
|
||||
public:
|
||||
explicit LtsBitfieldWidget(QWidget *parent = nullptr, quint8 value = 0);
|
||||
public:
|
||||
explicit LtsBitfieldWidget(QWidget* parent = nullptr, quint8 value = 0);
|
||||
|
||||
signals:
|
||||
void valueChanged(quint8 newValue);
|
||||
void isEditableChanged(bool option);
|
||||
void hasCaptionChanged(bool option);
|
||||
signals:
|
||||
void valueChanged(quint8 newValue);
|
||||
void isEditableChanged(bool option);
|
||||
void hasCaptionChanged(bool option);
|
||||
|
||||
public slots:
|
||||
|
||||
public slots:
|
||||
|
||||
void setValue(quint8 value);
|
||||
void setValue(quint8 value);
|
||||
|
||||
|
||||
void setEditable(bool editable);
|
||||
|
||||
void setEditable(bool editable);
|
||||
void setHasCaption(bool hasCaption);
|
||||
|
||||
|
||||
void setOnColor(const QColor& onColor);
|
||||
|
||||
void setHasCaption(bool hasCaption);
|
||||
void setOffColor(const QColor& offColor);
|
||||
|
||||
|
||||
public:
|
||||
quint8 value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void setOnColor(const QColor &onColor);
|
||||
bool isEditable() const
|
||||
{
|
||||
return m_isEditable;
|
||||
}
|
||||
|
||||
|
||||
bool hasCaption() const
|
||||
{
|
||||
return m_hasCaption;
|
||||
}
|
||||
|
||||
void setOffColor(const QColor &offColor);
|
||||
QColor onColor() const
|
||||
{
|
||||
return m_onColor;
|
||||
}
|
||||
|
||||
QColor offColor() const
|
||||
{
|
||||
return m_offColor;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
quint8 value() const { return m_value; }
|
||||
void paintEvent(QPaintEvent* pe) override;
|
||||
|
||||
|
||||
private:
|
||||
quint8 m_value = 0;
|
||||
|
||||
bool isEditable() const { return m_isEditable; }
|
||||
bool m_isEditable = true;
|
||||
bool m_hasCaption = true;
|
||||
|
||||
|
||||
|
||||
bool hasCaption() const { return m_hasCaption; }
|
||||
|
||||
|
||||
|
||||
QColor onColor() const {return m_onColor;}
|
||||
|
||||
|
||||
|
||||
QColor offColor() const {return m_offColor;}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
|
||||
|
||||
void paintEvent(QPaintEvent *pe) override;
|
||||
|
||||
private:
|
||||
quint8 m_value = 0;
|
||||
|
||||
bool m_isEditable = true;
|
||||
bool m_hasCaption = true;
|
||||
|
||||
QColor m_onColor = Qt::black;
|
||||
QColor m_offColor = Qt::white;
|
||||
QColor m_onColor = Qt::black;
|
||||
QColor m_offColor = Qt::white;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+103
-105
@@ -1,131 +1,129 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_abstract_table_model.h"
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class LtsCheckableTableModel : public LtsAbstractTableModel<T>
|
||||
template <class T> class LtsCheckableTableModel : public LtsAbstractTableModel<T>
|
||||
{
|
||||
public:
|
||||
LtsCheckableTableModel(const QVector<QString> &header, int checkableColumn, QObject *parent)
|
||||
: LtsAbstractTableModel<T>(header, parent)
|
||||
, m_checkableColumn(checkableColumn)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
|
||||
{
|
||||
if (role == Qt::CheckStateRole && index.column() == m_checkableColumn && LtsAbstractTableModel<T>::indexIsValid(index))
|
||||
return LtsAbstractTableModel<T>::m_vecData.at(index.row()).first ? Qt::Checked : Qt::Unchecked;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override
|
||||
{
|
||||
if (role == Qt::CheckStateRole)
|
||||
public:
|
||||
LtsCheckableTableModel(const QVector<QString>& header, int checkableColumn, QObject* parent)
|
||||
: LtsAbstractTableModel<T>(header, parent), m_checkableColumn(checkableColumn)
|
||||
{
|
||||
switchCheckbox(index);
|
||||
return true;
|
||||
}
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override
|
||||
{
|
||||
Qt::ItemFlags flags(LtsWidgets::LtsAbstractTableModel<T>::flags(index) & ~Qt::ItemIsSelectable);
|
||||
if (index.column() == m_checkableColumn)
|
||||
return flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
QVector<int> getCheckedIds() const
|
||||
{
|
||||
QVector<int> ids;
|
||||
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
const T &entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
if (entry.first)
|
||||
ids << entry.second.id();
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
QVector<int> getUncheckedIds() const
|
||||
{
|
||||
QVector<int> ids;
|
||||
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
|
||||
{
|
||||
const T &entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
if (!entry.first)
|
||||
ids << entry.second.id();
|
||||
if (role == Qt::CheckStateRole && index.column() == m_checkableColumn &&
|
||||
LtsAbstractTableModel<T>::indexIsValid(index))
|
||||
return LtsAbstractTableModel<T>::m_vecData.at(index.row()).first ? Qt::Checked : Qt::Unchecked;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
bool setChecked(const QVector<int> &vecCheckedIds)
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override
|
||||
{
|
||||
T &entry = LtsAbstractTableModel<T>::m_vecData[row];
|
||||
bool bContains = vecCheckedIds.contains(entry.second.id());
|
||||
if (entry.first != bContains)
|
||||
{
|
||||
entry.first = bContains;
|
||||
const QModelIndex idx(LtsAbstractTableModel<T>::index(row, m_checkableColumn, QModelIndex()));
|
||||
emit LtsAbstractTableModel<T>::dataChanged(idx, idx, {Qt::CheckStateRole});
|
||||
}
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
switchCheckbox(index);
|
||||
return true;
|
||||
}
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool isFiltered(const T &data, DataModification modType) const override
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(modType);
|
||||
return false;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void switchCheckbox(const QModelIndex &index)
|
||||
{
|
||||
auto entry = LtsAbstractTableModel<T>::getRowData(index.row());
|
||||
entry.first = !entry.first;
|
||||
LtsAbstractTableModel<T>::setRowData(index.row(), entry);
|
||||
}
|
||||
|
||||
void selectAll()
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override
|
||||
{
|
||||
T entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
entry.first = true;
|
||||
LtsAbstractTableModel<T>::setRowData(row, entry);
|
||||
}
|
||||
}
|
||||
Qt::ItemFlags flags(LtsWidgets::LtsAbstractTableModel<T>::flags(index) & ~Qt::ItemIsSelectable);
|
||||
if (index.column() == m_checkableColumn)
|
||||
return flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
|
||||
void unselectAll()
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
return flags;
|
||||
}
|
||||
|
||||
QVector<int> getCheckedIds() const
|
||||
{
|
||||
T entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
entry.first = false;
|
||||
LtsAbstractTableModel<T>::setRowData(row, entry);
|
||||
QVector<int> ids;
|
||||
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
const T& entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
if (entry.first)
|
||||
ids << entry.second.id();
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int m_checkableColumn;
|
||||
QVector<int> getUncheckedIds() const
|
||||
{
|
||||
QVector<int> ids;
|
||||
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
const T& entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
if (!entry.first)
|
||||
ids << entry.second.id();
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
bool setChecked(const QVector<int>& vecCheckedIds)
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
T& entry = LtsAbstractTableModel<T>::m_vecData[row];
|
||||
bool bContains = vecCheckedIds.contains(entry.second.id());
|
||||
if (entry.first != bContains)
|
||||
{
|
||||
entry.first = bContains;
|
||||
const QModelIndex idx(LtsAbstractTableModel<T>::index(row, m_checkableColumn, QModelIndex()));
|
||||
emit LtsAbstractTableModel<T>::dataChanged(idx, idx, {Qt::CheckStateRole});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isFiltered(const T& data, DataModification modType) const override
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(modType);
|
||||
return false;
|
||||
}
|
||||
|
||||
public slots:
|
||||
|
||||
void switchCheckbox(const QModelIndex& index)
|
||||
{
|
||||
auto entry = LtsAbstractTableModel<T>::getRowData(index.row());
|
||||
entry.first = !entry.first;
|
||||
LtsAbstractTableModel<T>::setRowData(index.row(), entry);
|
||||
}
|
||||
|
||||
void selectAll()
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
T entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
entry.first = true;
|
||||
LtsAbstractTableModel<T>::setRowData(row, entry);
|
||||
}
|
||||
}
|
||||
|
||||
void unselectAll()
|
||||
{
|
||||
for (int row = 0; row < LtsAbstractTableModel<T>::rowCount(); ++row)
|
||||
{
|
||||
T entry = LtsAbstractTableModel<T>::m_vecData.at(row);
|
||||
entry.first = false;
|
||||
LtsAbstractTableModel<T>::setRowData(row, entry);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int m_checkableColumn;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+92
-98
@@ -1,156 +1,150 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_column_filter_proxy_model.h"
|
||||
|
||||
#include <LtsUtilsCore/variant_operators.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsColumnFilterProxyModel::LtsColumnFilterProxyModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
LtsColumnFilterProxyModel::LtsColumnFilterProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool LtsColumnFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
bool LtsColumnFilterProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||
{
|
||||
return LtsUtils::lessThan(sourceModel()->data(left), sourceModel()->data(right));
|
||||
return LtsUtils::lessThan(sourceModel()->data(left), sourceModel()->data(right));
|
||||
}
|
||||
|
||||
void LtsColumnFilterProxyModel::onSetColumnStringFilter(const QString &newFilterString, int column)
|
||||
void LtsColumnFilterProxyModel::onSetColumnStringFilter(const QString& newFilterString, int column)
|
||||
{
|
||||
setColumnStringFilter(newFilterString, column);
|
||||
setColumnStringFilter(newFilterString, column);
|
||||
}
|
||||
|
||||
void LtsColumnFilterProxyModel::onSetColumnDataFilter(const QVariant &newFilterData, int column)
|
||||
void LtsColumnFilterProxyModel::onSetColumnDataFilter(const QVariant& newFilterData, int column)
|
||||
{
|
||||
setColumnDataFilter(newFilterData, column);
|
||||
setColumnDataFilter(newFilterData, column);
|
||||
}
|
||||
|
||||
void LtsColumnFilterProxyModel::setColumnStringFilter(const QString &newFilterString, int column)
|
||||
void LtsColumnFilterProxyModel::setColumnStringFilter(const QString& newFilterString, int column)
|
||||
{
|
||||
if (column < 0)
|
||||
return;
|
||||
auto it = m_columnStringFilters.find(column);
|
||||
if (newFilterString.isEmpty())
|
||||
{
|
||||
if (it == m_columnStringFilters.end())
|
||||
return;
|
||||
m_columnStringFilters.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto rx = QRegularExpression(newFilterString,
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
if (it == m_columnStringFilters.end())
|
||||
if (column < 0)
|
||||
return;
|
||||
auto it = m_columnStringFilters.find(column);
|
||||
if (newFilterString.isEmpty())
|
||||
{
|
||||
m_columnStringFilters.insert(column, rx);
|
||||
if (it == m_columnStringFilters.end())
|
||||
return;
|
||||
m_columnStringFilters.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rx == it.value())
|
||||
return;
|
||||
it.value() = rx;
|
||||
auto rx = QRegularExpression(newFilterString, QRegularExpression::CaseInsensitiveOption);
|
||||
if (it == m_columnStringFilters.end())
|
||||
{
|
||||
m_columnStringFilters.insert(column, rx);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rx == it.value())
|
||||
return;
|
||||
it.value() = rx;
|
||||
}
|
||||
}
|
||||
}
|
||||
invalidateFilter();
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void LtsColumnFilterProxyModel::setColumnDataFilter(const QVariant &newFilterData, int column)
|
||||
void LtsColumnFilterProxyModel::setColumnDataFilter(const QVariant& newFilterData, int column)
|
||||
{
|
||||
if (column < 0)
|
||||
return;
|
||||
auto it = m_columnDataFilters.find(column);
|
||||
if (newFilterData.isNull())
|
||||
{
|
||||
if (it == m_columnDataFilters.end())
|
||||
return;
|
||||
m_columnDataFilters.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (it == m_columnDataFilters.end())
|
||||
if (column < 0)
|
||||
return;
|
||||
auto it = m_columnDataFilters.find(column);
|
||||
if (newFilterData.isNull())
|
||||
{
|
||||
m_columnDataFilters[column] = newFilterData;
|
||||
if (it == m_columnDataFilters.end())
|
||||
return;
|
||||
m_columnDataFilters.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newFilterData == it.value())
|
||||
return;
|
||||
it.value() = newFilterData;
|
||||
if (it == m_columnDataFilters.end())
|
||||
{
|
||||
m_columnDataFilters[column] = newFilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newFilterData == it.value())
|
||||
return;
|
||||
it.value() = newFilterData;
|
||||
}
|
||||
}
|
||||
}
|
||||
invalidateFilter();
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
|
||||
bool LtsColumnFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||
bool LtsColumnFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
||||
{
|
||||
|
||||
const auto sm = sourceModel();
|
||||
bool bRet = true;
|
||||
for (auto it = m_columnDataFilters.begin(); bRet && it != m_columnDataFilters.end(); ++it)
|
||||
{
|
||||
const QModelIndex idx = sm->index(source_row, it.key(), source_parent);
|
||||
const QVariant _data = sm->data(idx, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole).toString();
|
||||
bRet = _data == it.value();
|
||||
if (!bRet)
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto it = m_columnStringFilters.begin(); bRet && it != m_columnStringFilters.end(); ++it)
|
||||
{
|
||||
const QRegularExpression &rx = it.value();
|
||||
if (!rx.isValid())
|
||||
continue;
|
||||
const QModelIndex idx = sm->index(source_row, it.key(), source_parent);
|
||||
const QString _data = sm->data(idx, Qt::DisplayRole).toString();
|
||||
bRet = _data.contains(rx);
|
||||
if (!bRet)
|
||||
break;
|
||||
}
|
||||
const auto sm = sourceModel();
|
||||
bool bRet = true;
|
||||
for (auto it = m_columnDataFilters.begin(); bRet && it != m_columnDataFilters.end(); ++it)
|
||||
{
|
||||
const QModelIndex idx = sm->index(source_row, it.key(), source_parent);
|
||||
const QVariant _data = sm->data(idx, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole).toString();
|
||||
bRet = _data == it.value();
|
||||
if (!bRet)
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto it = m_columnStringFilters.begin(); bRet && it != m_columnStringFilters.end(); ++it)
|
||||
{
|
||||
const QRegularExpression& rx = it.value();
|
||||
if (!rx.isValid())
|
||||
continue;
|
||||
const QModelIndex idx = sm->index(source_row, it.key(), source_parent);
|
||||
const QString _data = sm->data(idx, Qt::DisplayRole).toString();
|
||||
bRet = _data.contains(rx);
|
||||
if (!bRet)
|
||||
break;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||
if (!bRet && m_bRecursiveFiltering)
|
||||
{
|
||||
const QModelIndex idx = sm->index(source_row, 0, source_parent);
|
||||
if (checkIfOneChildIsVisible(idx))
|
||||
return true;
|
||||
}
|
||||
if (!bRet && m_bRecursiveFiltering)
|
||||
{
|
||||
const QModelIndex idx = sm->index(source_row, 0, source_parent);
|
||||
if (checkIfOneChildIsVisible(idx))
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return bRet;
|
||||
return bRet;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||
void LtsColumnFilterProxyModel::setRecursiveFilteringEnabled(bool recursive)
|
||||
{
|
||||
if (m_bRecursiveFiltering == recursive)
|
||||
return;
|
||||
m_bRecursiveFiltering = recursive;
|
||||
invalidateFilter();
|
||||
if (m_bRecursiveFiltering == recursive)
|
||||
return;
|
||||
m_bRecursiveFiltering = recursive;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool LtsColumnFilterProxyModel::recursiveFilteringEnabled() const
|
||||
{
|
||||
return m_bRecursiveFiltering;
|
||||
return m_bRecursiveFiltering;
|
||||
}
|
||||
|
||||
bool LtsColumnFilterProxyModel::checkIfOneChildIsVisible(const QModelIndex &parent) const
|
||||
bool LtsColumnFilterProxyModel::checkIfOneChildIsVisible(const QModelIndex& parent) const
|
||||
{
|
||||
const auto sm = sourceModel();
|
||||
const int childCount = sm->rowCount(parent);
|
||||
for (int i = 0; i < childCount; ++i)
|
||||
{
|
||||
if (filterAcceptsRow(i, parent))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
const auto sm = sourceModel();
|
||||
const int childCount = sm->rowCount(parent);
|
||||
for (int i = 0; i < childCount; ++i)
|
||||
{
|
||||
if (filterAcceptsRow(i, parent))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+178
-143
@@ -1,23 +1,19 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
#include "qcheckbox.h"
|
||||
#include "qpushbutton.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsDateTimeEditLe;
|
||||
class LtsDateTimeEdit;
|
||||
}
|
||||
class LtsDateTimeEditLe;
|
||||
class LtsDateTimeEdit;
|
||||
} // namespace Ui
|
||||
|
||||
class QLineEdit;
|
||||
class QShortcut;
|
||||
@@ -26,189 +22,228 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsDateTimeEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
|
||||
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
|
||||
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
|
||||
|
||||
public:
|
||||
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
public:
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
|
||||
explicit LtsDateTimeEdit(QWidget *parent = nullptr, bool withNowButton = true, bool checkable = false);
|
||||
~LtsDateTimeEdit();
|
||||
explicit LtsDateTimeEdit(QWidget* parent = nullptr, bool withNowButton = true, bool checkable = false);
|
||||
~LtsDateTimeEdit();
|
||||
|
||||
bool setupUiTouch();
|
||||
bool setupUiTouch();
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
bool isEmpty() const;
|
||||
bool isValidDate() const;
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
bool isEmpty() const;
|
||||
bool isValidDate() const;
|
||||
void setAutoForward(const bool af)
|
||||
{
|
||||
m_autoForward = af;
|
||||
}
|
||||
|
||||
void setAutoForward(const bool af) { m_autoForward = af; }
|
||||
bool getAutoForward() const { return m_autoForward; }
|
||||
bool getAutoForward() const
|
||||
{
|
||||
return m_autoForward;
|
||||
}
|
||||
|
||||
void setEditTimezone(const bool edit);
|
||||
bool getEditTimezone() const { return m_editTimezone; }
|
||||
void setEditTimezone(const bool edit);
|
||||
|
||||
void setWithButtons(const bool buttons);
|
||||
bool getWithButtons() const { return m_withButtons; }
|
||||
bool getEditTimezone() const
|
||||
{
|
||||
return m_editTimezone;
|
||||
}
|
||||
|
||||
void setWithSlider(const bool slider);
|
||||
bool getWithSlider() const { return m_withSlider; }
|
||||
void setWithButtons(const bool buttons);
|
||||
|
||||
void setReadOnly(const bool readOnly);
|
||||
bool isReadOnly() const { return m_readOnly; }
|
||||
bool getWithButtons() const
|
||||
{
|
||||
return m_withButtons;
|
||||
}
|
||||
|
||||
void setCheckable(bool checkable);
|
||||
bool isCheckable() const { return m_checkable; }
|
||||
void setChecked(bool bChecked);
|
||||
bool isChecked() const;
|
||||
void setWithSlider(const bool slider);
|
||||
|
||||
void setWithNowButton(bool nowButton);
|
||||
bool withNowButton() const { return m_withNowButton; }
|
||||
bool getWithSlider() const
|
||||
{
|
||||
return m_withSlider;
|
||||
}
|
||||
|
||||
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
qint64 minimumTimeMSec() const { return m_minTimeMSec; }
|
||||
void setReadOnly(const bool readOnly);
|
||||
|
||||
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
qint64 maximumTimeMSec() const { return m_maxTimeMSec; }
|
||||
bool isReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max) { setMinimumTimeMSec(min); setMaximumTimeMSec(max); }
|
||||
void setCheckable(bool checkable);
|
||||
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback &cb);
|
||||
bool isCheckable() const
|
||||
{
|
||||
return m_checkable;
|
||||
}
|
||||
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
qint64 getTimezoneAsSecs() const;
|
||||
void setChecked(bool bChecked);
|
||||
bool isChecked() const;
|
||||
|
||||
void setSubWidgetsProperties(const QString &name, const QVariant &value);
|
||||
void setWithNowButton(bool nowButton);
|
||||
|
||||
Q_SIGNALS:
|
||||
void dateTimeChanged();
|
||||
void toggled(bool on);
|
||||
bool withNowButton() const
|
||||
{
|
||||
return m_withNowButton;
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
bool setMsecsSinceEpoch(qint64 msec, bool setToNearestPossible = true);
|
||||
void clear();
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
|
||||
private:
|
||||
void clearTimezone();
|
||||
qint64 minimumTimeMSec() const
|
||||
{
|
||||
return m_minTimeMSec;
|
||||
}
|
||||
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
|
||||
bool setMonth(int month);
|
||||
int getMonth() const;
|
||||
qint64 maximumTimeMSec() const
|
||||
{
|
||||
return m_maxTimeMSec;
|
||||
}
|
||||
|
||||
bool setDay(int day);
|
||||
int getDay() const;
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max)
|
||||
{
|
||||
setMinimumTimeMSec(min);
|
||||
setMaximumTimeMSec(max);
|
||||
}
|
||||
|
||||
bool setHHMMSS(int hour, int minute, int second);
|
||||
int getHour() const;
|
||||
int getMinute() const;
|
||||
int getSecond() const;
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback& cb);
|
||||
|
||||
bool setYear(int year);
|
||||
int getYear() const;
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
qint64 getTimezoneAsSecs() const;
|
||||
|
||||
bool isEmptyDay() const;
|
||||
bool isEmptyHHMMSS() const;
|
||||
bool isEmptyTimezone() const;
|
||||
bool isEmptyMonth() const;
|
||||
bool isEmptyYear() const;
|
||||
void setSubWidgetsProperties(const QString& name, const QVariant& value);
|
||||
|
||||
bool hasFocus() const;
|
||||
Q_SIGNALS:
|
||||
void dateTimeChanged();
|
||||
void toggled(bool on);
|
||||
|
||||
bool isDataAcceptable();
|
||||
public Q_SLOTS:
|
||||
bool setMsecsSinceEpoch(qint64 msec, bool setToNearestPossible = true);
|
||||
void clear();
|
||||
|
||||
void showInvalidData(bool setFocus);
|
||||
private:
|
||||
void clearTimezone();
|
||||
|
||||
bool isLineEditDataAcceptable(QLineEdit *le) const;
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
|
||||
bool isDayAcceptable() const;
|
||||
bool isHHMMSSAcceptable() const;
|
||||
bool isMonthAcceptable() const;
|
||||
bool isYearAcceptable() const;
|
||||
bool isTzAcceptable() const;
|
||||
bool setMonth(int month);
|
||||
int getMonth() const;
|
||||
|
||||
QCheckBox* checkBox() const;
|
||||
QPushButton* pbNow() const;
|
||||
bool setDay(int day);
|
||||
int getDay() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void setFixedDateTime();
|
||||
void setOffsetDateTime();
|
||||
bool setHHMMSS(int hour, int minute, int second);
|
||||
int getHour() const;
|
||||
int getMinute() const;
|
||||
int getSecond() const;
|
||||
|
||||
void setSliderValue(int val);
|
||||
void valueDayChanged(const QString &str);
|
||||
void fixupHHMMSS();
|
||||
void valueMonthChanged(const QString &str);
|
||||
void valueMonthChanged2(const QString &str);
|
||||
void valueTimezoneChangedStr(const QString &str);
|
||||
void valueTimezoneChangedInt(int newTimezone);
|
||||
void valueYearChanged(const QString &str);
|
||||
bool setYear(int year);
|
||||
int getYear() const;
|
||||
|
||||
void onBackHourClicked();
|
||||
void onBackMinuteClicked();
|
||||
void onBackSecondClicked();
|
||||
void onForwardSecondClicked();
|
||||
void onForwardMinuteClicked();
|
||||
void onForwardHourClicked();
|
||||
bool isEmptyDay() const;
|
||||
bool isEmptyHHMMSS() const;
|
||||
bool isEmptyTimezone() const;
|
||||
bool isEmptyMonth() const;
|
||||
bool isEmptyYear() const;
|
||||
|
||||
void onCheckBoxChanged();
|
||||
void disableControls();
|
||||
void enableControls();
|
||||
void enaDisaControls(bool bEnable);
|
||||
bool hasFocus() const;
|
||||
|
||||
void onFocusOutHHMMSS();
|
||||
void onFocusOutTZ();
|
||||
void onFocusOutDay();
|
||||
void onFocusOutMonth();
|
||||
void onFocusOutYear();
|
||||
bool isDataAcceptable();
|
||||
|
||||
void onFocusOutBackspace();
|
||||
void onFocusOut();
|
||||
void showInvalidData(bool setFocus);
|
||||
|
||||
void onHmsWheelEvent(bool bForward, int cursorPos);
|
||||
void onDayWheelEvent(bool bForward, int cursorPos);
|
||||
void onMonthWheelEvent(bool bForward, int cursorPos);
|
||||
void onYearWheelEvent(bool bForward, int cursorPos);
|
||||
bool isLineEditDataAcceptable(QLineEdit* le) const;
|
||||
|
||||
private:
|
||||
Ui::LtsDateTimeEditLe *m_uiLe{nullptr};
|
||||
Ui::LtsDateTimeEdit *m_uiTouch{nullptr};
|
||||
QShortcut *m_scFixed = nullptr;
|
||||
QShortcut *m_scOffset = nullptr;
|
||||
bool isDayAcceptable() const;
|
||||
bool isHHMMSSAcceptable() const;
|
||||
bool isMonthAcceptable() const;
|
||||
bool isYearAcceptable() const;
|
||||
bool isTzAcceptable() const;
|
||||
|
||||
CurrentTimeCallback m_getCurrentTimeCallback = nullptr;
|
||||
QCheckBox* checkBox() const;
|
||||
QPushButton* pbNow() const;
|
||||
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
private Q_SLOTS:
|
||||
void setFixedDateTime();
|
||||
void setOffsetDateTime();
|
||||
|
||||
qint64 m_curTimeMSec = -1;
|
||||
void setSliderValue(int val);
|
||||
void valueDayChanged(const QString& str);
|
||||
void fixupHHMMSS();
|
||||
void valueMonthChanged(const QString& str);
|
||||
void valueMonthChanged2(const QString& str);
|
||||
void valueTimezoneChangedStr(const QString& str);
|
||||
void valueTimezoneChangedInt(int newTimezone);
|
||||
void valueYearChanged(const QString& str);
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_checkable = false;
|
||||
bool m_withNowButton = false;
|
||||
void onBackHourClicked();
|
||||
void onBackMinuteClicked();
|
||||
void onBackSecondClicked();
|
||||
void onForwardSecondClicked();
|
||||
void onForwardMinuteClicked();
|
||||
void onForwardHourClicked();
|
||||
|
||||
int m_minMonth{0};
|
||||
int m_maxMonth{0};
|
||||
void onCheckBoxChanged();
|
||||
void disableControls();
|
||||
void enableControls();
|
||||
void enaDisaControls(bool bEnable);
|
||||
|
||||
void onFocusOutHHMMSS();
|
||||
void onFocusOutTZ();
|
||||
void onFocusOutDay();
|
||||
void onFocusOutMonth();
|
||||
void onFocusOutYear();
|
||||
|
||||
bool m_backspacePressed = false;
|
||||
bool m_recursionAvoid = false;
|
||||
bool m_dateIsAcceptable = false;
|
||||
void onFocusOutBackspace();
|
||||
void onFocusOut();
|
||||
|
||||
void onHmsWheelEvent(bool bForward, int cursorPos);
|
||||
void onDayWheelEvent(bool bForward, int cursorPos);
|
||||
void onMonthWheelEvent(bool bForward, int cursorPos);
|
||||
void onYearWheelEvent(bool bForward, int cursorPos);
|
||||
|
||||
private:
|
||||
Ui::LtsDateTimeEditLe* m_uiLe{nullptr};
|
||||
Ui::LtsDateTimeEdit* m_uiTouch{nullptr};
|
||||
QShortcut* m_scFixed = nullptr;
|
||||
QShortcut* m_scOffset = nullptr;
|
||||
|
||||
CurrentTimeCallback m_getCurrentTimeCallback = nullptr;
|
||||
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
|
||||
qint64 m_curTimeMSec = -1;
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_checkable = false;
|
||||
bool m_withNowButton = false;
|
||||
|
||||
int m_minMonth{0};
|
||||
int m_maxMonth{0};
|
||||
|
||||
bool m_backspacePressed = false;
|
||||
bool m_recursionAvoid = false;
|
||||
bool m_dateIsAcceptable = false;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+31
-29
@@ -1,44 +1,46 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QLineEdit::QLineEdit;
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QLineEdit::QLineEdit;
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
Q_SIGNALS:
|
||||
void focusOutBackspace();
|
||||
void focusOut();
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* e) override;
|
||||
void focusOutEvent(QFocusEvent* event) override;
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
Q_SIGNALS:
|
||||
void focusOutBackspace();
|
||||
void focusOut();
|
||||
};
|
||||
|
||||
class DigitsLineEdit final : public LineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DigitsLineEdit(QWidget *parent = nullptr);
|
||||
Q_OBJECT
|
||||
public:
|
||||
DigitsLineEdit(QWidget* parent = nullptr);
|
||||
|
||||
void setExactNumDigits(int num);
|
||||
void setCursorPosition(int curPos);
|
||||
void setValue(int val);
|
||||
int getValue() const;
|
||||
Q_SIGNALS:
|
||||
void wheelEventReceived(bool bForward, int cursorPos);
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
private:
|
||||
int m_exactNumDigits = -1;
|
||||
void setExactNumDigits(int num);
|
||||
void setCursorPosition(int curPos);
|
||||
void setValue(int val);
|
||||
int getValue() const;
|
||||
Q_SIGNALS:
|
||||
void wheelEventReceived(bool bForward, int cursorPos);
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
private:
|
||||
int m_exactNumDigits = -1;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+174
-139
@@ -1,21 +1,17 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsDateTimeEditLe;
|
||||
class LtsDateTimeEdit;
|
||||
}
|
||||
class LtsDateTimeEditLe;
|
||||
class LtsDateTimeEdit;
|
||||
} // namespace Ui
|
||||
|
||||
class QLineEdit;
|
||||
class QShortcut;
|
||||
@@ -24,184 +20,223 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsDateTimeEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool withCheckBox READ withCheckBox WRITE setWithCheckBox)
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool withCheckBox READ withCheckBox WRITE setWithCheckBox)
|
||||
|
||||
public:
|
||||
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
public:
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
|
||||
explicit LtsDateTimeEdit(QWidget *parent = nullptr, bool withNowButton = true, bool withCheckBox = false);
|
||||
~LtsDateTimeEdit();
|
||||
explicit LtsDateTimeEdit(QWidget* parent = nullptr, bool withNowButton = true, bool withCheckBox = false);
|
||||
~LtsDateTimeEdit();
|
||||
|
||||
bool setupUiTouch();
|
||||
bool setupUiTouch();
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
bool isEmpty() const;
|
||||
bool isValidDate() const;
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
bool isEmpty() const;
|
||||
bool isValidDate() const;
|
||||
void setAutoForward(const bool af)
|
||||
{
|
||||
m_autoForward = af;
|
||||
}
|
||||
|
||||
void setAutoForward(const bool af) { m_autoForward = af; }
|
||||
bool getAutoForward() const { return m_autoForward; }
|
||||
bool getAutoForward() const
|
||||
{
|
||||
return m_autoForward;
|
||||
}
|
||||
|
||||
void setEditTimezone(const bool edit);
|
||||
bool getEditTimezone() const { return m_editTimezone; }
|
||||
void setEditTimezone(const bool edit);
|
||||
|
||||
void setWithButtons(const bool buttons);
|
||||
bool getWithButtons() const { return m_withButtons; }
|
||||
bool getEditTimezone() const
|
||||
{
|
||||
return m_editTimezone;
|
||||
}
|
||||
|
||||
void setWithSlider(const bool slider);
|
||||
bool getWithSlider() const { return m_withSlider; }
|
||||
void setWithButtons(const bool buttons);
|
||||
|
||||
void setReadOnly(const bool readOnly);
|
||||
bool isReadOnly() const { return m_readOnly; }
|
||||
bool getWithButtons() const
|
||||
{
|
||||
return m_withButtons;
|
||||
}
|
||||
|
||||
void setWithCheckBox(bool checkBoxEnabled);
|
||||
bool withCheckBox() const { return m_withCheckBox; }
|
||||
void setCheckBoxChecked(bool bChecked);
|
||||
bool isCheckBoxChecked() const;
|
||||
void setWithSlider(const bool slider);
|
||||
|
||||
void setWithNowButton(bool nowButton);
|
||||
bool withNowButton() const { return m_withNowButton; }
|
||||
bool getWithSlider() const
|
||||
{
|
||||
return m_withSlider;
|
||||
}
|
||||
|
||||
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
qint64 minimumTimeMSec() const { return m_minTimeMSec; }
|
||||
void setReadOnly(const bool readOnly);
|
||||
|
||||
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
qint64 maximumTimeMSec() const { return m_maxTimeMSec; }
|
||||
bool isReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max) { setMinimumTimeMSec(min); setMaximumTimeMSec(max); }
|
||||
void setWithCheckBox(bool checkBoxEnabled);
|
||||
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback &cb);
|
||||
bool withCheckBox() const
|
||||
{
|
||||
return m_withCheckBox;
|
||||
}
|
||||
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
qint64 getTimezoneAsSecs() const;
|
||||
void setCheckBoxChecked(bool bChecked);
|
||||
bool isCheckBoxChecked() const;
|
||||
|
||||
void setSubWidgetsProperties(const QString &name, const QVariant &value);
|
||||
void setWithNowButton(bool nowButton);
|
||||
|
||||
Q_SIGNALS:
|
||||
void dateTimeChanged();
|
||||
bool withNowButton() const
|
||||
{
|
||||
return m_withNowButton;
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
bool setMsecsSinceEpoch(qint64 msec, bool setToNearestPossible = true);
|
||||
void clear();
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
|
||||
private:
|
||||
void clearTimezone();
|
||||
qint64 minimumTimeMSec() const
|
||||
{
|
||||
return m_minTimeMSec;
|
||||
}
|
||||
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
|
||||
bool setMonth(int month);
|
||||
int getMonth() const;
|
||||
qint64 maximumTimeMSec() const
|
||||
{
|
||||
return m_maxTimeMSec;
|
||||
}
|
||||
|
||||
bool setDay(int day);
|
||||
int getDay() const;
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max)
|
||||
{
|
||||
setMinimumTimeMSec(min);
|
||||
setMaximumTimeMSec(max);
|
||||
}
|
||||
|
||||
bool setHHMMSS(int hour, int minute, int second);
|
||||
int getHour() const;
|
||||
int getMinute() const;
|
||||
int getSecond() const;
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback& cb);
|
||||
|
||||
bool setYear(int year);
|
||||
int getYear() const;
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
qint64 getTimezoneAsSecs() const;
|
||||
|
||||
bool isEmptyDay() const;
|
||||
bool isEmptyHHMMSS() const;
|
||||
bool isEmptyTimezone() const;
|
||||
bool isEmptyMonth() const;
|
||||
bool isEmptyYear() const;
|
||||
void setSubWidgetsProperties(const QString& name, const QVariant& value);
|
||||
|
||||
bool hasFocus() const;
|
||||
Q_SIGNALS:
|
||||
void dateTimeChanged();
|
||||
|
||||
bool isDataAcceptable();
|
||||
public Q_SLOTS:
|
||||
bool setMsecsSinceEpoch(qint64 msec, bool setToNearestPossible = true);
|
||||
void clear();
|
||||
|
||||
void showInvalidData(bool setFocus);
|
||||
private:
|
||||
void clearTimezone();
|
||||
|
||||
bool isLineEditDataAcceptable(QLineEdit *le) const;
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
|
||||
bool isDayAcceptable() const;
|
||||
bool isHHMMSSAcceptable() const;
|
||||
bool isMonthAcceptable() const;
|
||||
bool isYearAcceptable() const;
|
||||
bool isTzAcceptable() const;
|
||||
bool setMonth(int month);
|
||||
int getMonth() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void setFixedDateTime();
|
||||
void setOffsetDateTime();
|
||||
bool setDay(int day);
|
||||
int getDay() const;
|
||||
|
||||
void setSliderValue(int val);
|
||||
void valueDayChanged(const QString &str);
|
||||
void fixupHHMMSS();
|
||||
void valueMonthChanged(const QString &str);
|
||||
void valueMonthChanged2(const QString &str);
|
||||
void valueTimezoneChangedStr(const QString &str);
|
||||
void valueTimezoneChangedInt(int newTimezone);
|
||||
void valueYearChanged(const QString &str);
|
||||
bool setHHMMSS(int hour, int minute, int second);
|
||||
int getHour() const;
|
||||
int getMinute() const;
|
||||
int getSecond() const;
|
||||
|
||||
void onBackHourClicked();
|
||||
void onBackMinuteClicked();
|
||||
void onBackSecondClicked();
|
||||
void onForwardSecondClicked();
|
||||
void onForwardMinuteClicked();
|
||||
void onForwardHourClicked();
|
||||
bool setYear(int year);
|
||||
int getYear() const;
|
||||
|
||||
void onCheckBoxChanged();
|
||||
void disableControls();
|
||||
void enableControls();
|
||||
void enaDisaControls(bool bEnable);
|
||||
bool isEmptyDay() const;
|
||||
bool isEmptyHHMMSS() const;
|
||||
bool isEmptyTimezone() const;
|
||||
bool isEmptyMonth() const;
|
||||
bool isEmptyYear() const;
|
||||
|
||||
void onFocusOutHHMMSS();
|
||||
void onFocusOutTZ();
|
||||
void onFocusOutDay();
|
||||
void onFocusOutMonth();
|
||||
void onFocusOutYear();
|
||||
bool hasFocus() const;
|
||||
|
||||
void onFocusOutBackspace();
|
||||
void onFocusOut();
|
||||
bool isDataAcceptable();
|
||||
|
||||
void onHmsWheelEvent(bool bForward, int cursorPos);
|
||||
void onDayWheelEvent(bool bForward, int cursorPos);
|
||||
void onMonthWheelEvent(bool bForward, int cursorPos);
|
||||
void onYearWheelEvent(bool bForward, int cursorPos);
|
||||
void showInvalidData(bool setFocus);
|
||||
|
||||
private:
|
||||
Ui::LtsDateTimeEditLe *m_uiLe{nullptr};
|
||||
Ui::LtsDateTimeEdit *m_uiTouch{nullptr};
|
||||
QShortcut *m_scFixed = nullptr;
|
||||
QShortcut *m_scOffset = nullptr;
|
||||
bool isLineEditDataAcceptable(QLineEdit* le) const;
|
||||
|
||||
CurrentTimeCallback m_getCurrentTimeCallback = nullptr;
|
||||
bool isDayAcceptable() const;
|
||||
bool isHHMMSSAcceptable() const;
|
||||
bool isMonthAcceptable() const;
|
||||
bool isYearAcceptable() const;
|
||||
bool isTzAcceptable() const;
|
||||
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
private Q_SLOTS:
|
||||
void setFixedDateTime();
|
||||
void setOffsetDateTime();
|
||||
|
||||
qint64 m_curTimeMSec = -1;
|
||||
void setSliderValue(int val);
|
||||
void valueDayChanged(const QString& str);
|
||||
void fixupHHMMSS();
|
||||
void valueMonthChanged(const QString& str);
|
||||
void valueMonthChanged2(const QString& str);
|
||||
void valueTimezoneChangedStr(const QString& str);
|
||||
void valueTimezoneChangedInt(int newTimezone);
|
||||
void valueYearChanged(const QString& str);
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_withCheckBox = false;
|
||||
bool m_withNowButton = false;
|
||||
void onBackHourClicked();
|
||||
void onBackMinuteClicked();
|
||||
void onBackSecondClicked();
|
||||
void onForwardSecondClicked();
|
||||
void onForwardMinuteClicked();
|
||||
void onForwardHourClicked();
|
||||
|
||||
int m_minMonth{0};
|
||||
int m_maxMonth{0};
|
||||
void onCheckBoxChanged();
|
||||
void disableControls();
|
||||
void enableControls();
|
||||
void enaDisaControls(bool bEnable);
|
||||
|
||||
void onFocusOutHHMMSS();
|
||||
void onFocusOutTZ();
|
||||
void onFocusOutDay();
|
||||
void onFocusOutMonth();
|
||||
void onFocusOutYear();
|
||||
|
||||
bool m_backspacePressed = false;
|
||||
bool m_recursionAvoid = false;
|
||||
bool m_dateIsAcceptable = false;
|
||||
void onFocusOutBackspace();
|
||||
void onFocusOut();
|
||||
|
||||
void onHmsWheelEvent(bool bForward, int cursorPos);
|
||||
void onDayWheelEvent(bool bForward, int cursorPos);
|
||||
void onMonthWheelEvent(bool bForward, int cursorPos);
|
||||
void onYearWheelEvent(bool bForward, int cursorPos);
|
||||
|
||||
private:
|
||||
Ui::LtsDateTimeEditLe* m_uiLe{nullptr};
|
||||
Ui::LtsDateTimeEdit* m_uiTouch{nullptr};
|
||||
QShortcut* m_scFixed = nullptr;
|
||||
QShortcut* m_scOffset = nullptr;
|
||||
|
||||
CurrentTimeCallback m_getCurrentTimeCallback = nullptr;
|
||||
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
|
||||
qint64 m_curTimeMSec = -1;
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_withCheckBox = false;
|
||||
bool m_withNowButton = false;
|
||||
|
||||
int m_minMonth{0};
|
||||
int m_maxMonth{0};
|
||||
|
||||
bool m_backspacePressed = false;
|
||||
bool m_recursionAvoid = false;
|
||||
bool m_dateIsAcceptable = false;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+228
-253
@@ -1,389 +1,364 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_date_time_edit_touch.h"
|
||||
|
||||
#include "ui_lts_date_time_edit_touch.h"
|
||||
|
||||
#include <ngltools/ngltools_dtg.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <QShortcut>
|
||||
#include <ngltools/ngltools_dtg.h>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsDateTimeEdit::LtsDateTimeEdit(QWidget *parent, bool withNowButton, bool withCheckBox)
|
||||
: QWidget(parent)
|
||||
, m_withCheckBox(withCheckBox)
|
||||
, m_withNowButton(withNowButton)
|
||||
, m_tzOffset(0)
|
||||
, m_minMonth(1)
|
||||
, m_maxMonth(12)
|
||||
, m_scFixed(new QShortcut(QKeySequence(Qt::ShiftModifier + Qt::Key_F2), this, SLOT(onSetFixedDateTime()), nullptr, Qt::WidgetWithChildrenShortcut))
|
||||
, m_scOffset(new QShortcut(QKeySequence(Qt::Key_F2), this, SLOT(onSetOffsetDateTime()), nullptr, Qt::WidgetWithChildrenShortcut))
|
||||
, m_getCurrentTimeCallback(nullptr)
|
||||
, m_ui(new Ui::LtsDateTimeEdit)
|
||||
LtsDateTimeEdit::LtsDateTimeEdit(QWidget* parent, bool withNowButton, bool withCheckBox)
|
||||
: QWidget(parent), m_withCheckBox(withCheckBox), m_withNowButton(withNowButton), m_tzOffset(0), m_minMonth(1),
|
||||
m_maxMonth(12), m_scFixed(new QShortcut(QKeySequence(Qt::ShiftModifier + Qt::Key_F2), this,
|
||||
SLOT(onSetFixedDateTime()), nullptr, Qt::WidgetWithChildrenShortcut)),
|
||||
m_scOffset(new QShortcut(QKeySequence(Qt::Key_F2), this, SLOT(onSetOffsetDateTime()), nullptr,
|
||||
Qt::WidgetWithChildrenShortcut)),
|
||||
m_getCurrentTimeCallback(nullptr), m_ui(new Ui::LtsDateTimeEdit)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
m_ui->setupUi(this);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
for (int i = 65; i < 91; i++)
|
||||
{
|
||||
if (QChar(i).toUpper() == QChar::fromLatin1('I'))
|
||||
continue;
|
||||
m_ui->cbxTimeZone->addItem(QChar(i), QChar(i));
|
||||
}
|
||||
|
||||
for (int i = 65; i < 91; i++ )
|
||||
{
|
||||
if (QChar(i).toUpper() == QChar::fromLatin1('I'))
|
||||
continue;
|
||||
m_ui->cbxTimeZone->addItem(QChar(i), QChar(i));
|
||||
connect(m_ui->pbNow, &QPushButton::clicked, this, &LtsDateTimeEdit::onSetOffsetDateTime);
|
||||
connect(m_ui->cbxMonth, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spDay, &QSpinBox::editingFinished, this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spHour, &QSpinBox::editingFinished, this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spMinutes, &QSpinBox::editingFinished, this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spSeconds, &QSpinBox::editingFinished, this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spYear, &QSpinBox::editingFinished, this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
|
||||
}
|
||||
connect(m_ui->checkBox, &QCheckBox::toggled, this, &LtsDateTimeEdit::onCheckBoxChanged);
|
||||
connect(m_ui->cbxTimeZone, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&LtsDateTimeEdit::onTimeZoneChanged);
|
||||
|
||||
connect(m_ui->pbNow, &QPushButton::clicked,
|
||||
this, &LtsDateTimeEdit::onSetOffsetDateTime);
|
||||
connect(m_ui->cbxMonth, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spDay, &QSpinBox::editingFinished,
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spHour, &QSpinBox::editingFinished,
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spMinutes, &QSpinBox::editingFinished,
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spSeconds, &QSpinBox::editingFinished,
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->spYear, &QSpinBox::editingFinished,
|
||||
this, &LtsDateTimeEdit::onDateTimeChanged);
|
||||
connect(m_ui->cbxMonth, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&LtsDateTimeEdit::onMonthChanged);
|
||||
|
||||
connect(m_ui->checkBox, &QCheckBox::toggled,
|
||||
this, &LtsDateTimeEdit::onCheckBoxChanged);
|
||||
connect(m_ui->cbxTimeZone, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &LtsDateTimeEdit::onTimeZoneChanged);
|
||||
m_tzOffset = DTG::timezone2Secs(QLatin1Char(DTG::timezone()).toLatin1());
|
||||
|
||||
connect(m_ui->cbxMonth, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &LtsDateTimeEdit::onMonthChanged);
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findText(QString(QLatin1Char(DTG::timezone()))));
|
||||
onTimeZoneChanged();
|
||||
setMinMaxMonth(1, 12);
|
||||
|
||||
m_tzOffset = DTG::timezone2Secs(QLatin1Char(DTG::timezone()).toLatin1());
|
||||
int offset = LtsUtils::OperatorSettings::getInstance()
|
||||
->value(QStringLiteral("TimeSettings"), QStringLiteral("Offset"), 0)
|
||||
.toLongLong() /
|
||||
1000;
|
||||
m_ui->pbNow->setToolTip(tr("Set to current time plus %n second(s) offset", "", offset));
|
||||
|
||||
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findText(QString(QLatin1Char(DTG::timezone()))));
|
||||
onTimeZoneChanged();
|
||||
setMinMaxMonth(1,12);
|
||||
updateDateTimeType();
|
||||
|
||||
|
||||
int offset = LtsUtils::OperatorSettings::getInstance()->value(QStringLiteral("TimeSettings"), QStringLiteral("Offset"), 0).toLongLong()/1000;
|
||||
m_ui->pbNow->setToolTip(tr("Set to current time plus %n second(s) offset", "", offset));
|
||||
|
||||
updateDateTimeType();
|
||||
|
||||
m_ui->checkBox->setVisible(m_withCheckBox);
|
||||
m_ui->pbNow->setVisible(m_withNowButton);
|
||||
m_ui->checkBox->setVisible(m_withCheckBox);
|
||||
m_ui->pbNow->setVisible(m_withNowButton);
|
||||
}
|
||||
|
||||
LtsDateTimeEdit::~LtsDateTimeEdit()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::updateDateTimeType()
|
||||
{
|
||||
switch (DTG::dateTimeType())
|
||||
{
|
||||
case DTG::DateTimeType::DTG:
|
||||
break;
|
||||
case DTG::DateTimeType::DDMMYYYY_HHMMSS_Z:
|
||||
break;
|
||||
case DTG::DateTimeType::DDMMYYYY_Z_HHMMSS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (DTG::dateTimeType())
|
||||
{
|
||||
case DTG::DateTimeType::DTG:
|
||||
break;
|
||||
case DTG::DateTimeType::DDMMYYYY_HHMMSS_Z:
|
||||
break;
|
||||
case DTG::DateTimeType::DDMMYYYY_Z_HHMMSS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool LtsDateTimeEdit::setTimezone(char tz)
|
||||
{
|
||||
QChar tzLocal = QChar(QLatin1Char(tz)).toUpper();
|
||||
if (tzLocal.toLatin1() == 'J')
|
||||
tzLocal = QLatin1Char('Z');
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findData(tzLocal));
|
||||
int offset = DTG::timezone2Secs(tzLocal.toLatin1());
|
||||
if (offset != m_tzOffset)
|
||||
{
|
||||
const auto ms = msecsSinceEpoch();
|
||||
m_tzOffset = offset;
|
||||
setMsecsSinceEpoch(ms+m_tzOffset);
|
||||
}
|
||||
return true;
|
||||
QChar tzLocal = QChar(QLatin1Char(tz)).toUpper();
|
||||
if (tzLocal.toLatin1() == 'J')
|
||||
tzLocal = QLatin1Char('Z');
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findData(tzLocal));
|
||||
int offset = DTG::timezone2Secs(tzLocal.toLatin1());
|
||||
if (offset != m_tzOffset)
|
||||
{
|
||||
const auto ms = msecsSinceEpoch();
|
||||
m_tzOffset = offset;
|
||||
setMsecsSinceEpoch(ms + m_tzOffset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
char LtsDateTimeEdit::getTimezone() const
|
||||
{
|
||||
QChar tz = m_ui->cbxTimeZone->currentText().at(0).toUpper();
|
||||
QChar tz = m_ui->cbxTimeZone->currentText().at(0).toUpper();
|
||||
|
||||
if (tz.toLatin1() == 'J')
|
||||
tz = QLatin1Char('Z');
|
||||
|
||||
if (tz.toLatin1() == 'J')
|
||||
tz = QLatin1Char('Z');
|
||||
|
||||
if (tz.isNull())
|
||||
return DTG::timezone();
|
||||
return tz.toLatin1();
|
||||
if (tz.isNull())
|
||||
return DTG::timezone();
|
||||
return tz.toLatin1();
|
||||
}
|
||||
|
||||
|
||||
void LtsDateTimeEdit::setMinMaxMonth(int minMonth, int maxMonth )
|
||||
void LtsDateTimeEdit::setMinMaxMonth(int minMonth, int maxMonth)
|
||||
{
|
||||
if (m_minMonth != minMonth)
|
||||
m_minMonth = minMonth;
|
||||
if (m_maxMonth != maxMonth)
|
||||
m_maxMonth = maxMonth;
|
||||
if (m_minMonth != minMonth)
|
||||
m_minMonth = minMonth;
|
||||
if (m_maxMonth != maxMonth)
|
||||
m_maxMonth = maxMonth;
|
||||
|
||||
int currentMonth = m_ui->cbxMonth->currentData().toInt();
|
||||
m_ui->cbxMonth->blockSignals(true);
|
||||
m_ui->cbxMonth->clear();
|
||||
for (int i =1; i<= 12 ; i++)
|
||||
{
|
||||
if (i < m_minMonth)
|
||||
continue;
|
||||
if (i > m_maxMonth)
|
||||
break;
|
||||
QDate date(1777,i,1);
|
||||
m_ui->cbxMonth->addItem(date.toString(QStringLiteral("MMM")),i);
|
||||
|
||||
}
|
||||
m_ui->cbxMonth->setCurrentIndex(m_ui->cbxMonth->findData(currentMonth));
|
||||
m_ui->cbxMonth->blockSignals(false);
|
||||
int currentMonth = m_ui->cbxMonth->currentData().toInt();
|
||||
m_ui->cbxMonth->blockSignals(true);
|
||||
m_ui->cbxMonth->clear();
|
||||
for (int i = 1; i <= 12; i++)
|
||||
{
|
||||
if (i < m_minMonth)
|
||||
continue;
|
||||
if (i > m_maxMonth)
|
||||
break;
|
||||
QDate date(1777, i, 1);
|
||||
m_ui->cbxMonth->addItem(date.toString(QStringLiteral("MMM")), i);
|
||||
}
|
||||
m_ui->cbxMonth->setCurrentIndex(m_ui->cbxMonth->findData(currentMonth));
|
||||
m_ui->cbxMonth->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
void LtsDateTimeEdit::setDateTime(const QDateTime &datetime)
|
||||
void LtsDateTimeEdit::setDateTime(const QDateTime& datetime)
|
||||
{
|
||||
if (!datetime.isValid() && m_withCheckBox)
|
||||
{
|
||||
m_ui->checkBox->setChecked(false);
|
||||
return;
|
||||
}
|
||||
if (!datetime.isValid() && m_withCheckBox)
|
||||
{
|
||||
m_ui->checkBox->setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QDateTime dt = datetime.toUTC().addSecs(m_tzOffset);
|
||||
dt.setOffsetFromUtc(m_tzOffset);
|
||||
QDateTime dt = datetime.toUTC().addSecs(m_tzOffset);
|
||||
dt.setOffsetFromUtc(m_tzOffset);
|
||||
|
||||
|
||||
QDateTime oldDateTime = dateTime();
|
||||
if (dt == oldDateTime)
|
||||
return;
|
||||
QDateTime oldDateTime = dateTime();
|
||||
if (dt == oldDateTime)
|
||||
return;
|
||||
|
||||
blockSignals(true);
|
||||
blockSignals(true);
|
||||
|
||||
m_ui->spDay->setValue(dt.date().day());
|
||||
m_ui->cbxMonth->setCurrentIndex(m_ui->cbxMonth->findData(dt.date().month()));
|
||||
|
||||
|
||||
|
||||
|
||||
m_ui->spYear->setValue(dt.date().year()-2000);
|
||||
m_ui->spDay->setValue(dt.date().day());
|
||||
m_ui->cbxMonth->setCurrentIndex(m_ui->cbxMonth->findData(dt.date().month()));
|
||||
|
||||
m_ui->spHour->setValue(dt.time().hour());
|
||||
m_ui->spMinutes->setValue(dt.time().minute());
|
||||
m_ui->spSeconds->setValue(dt.time().second());
|
||||
m_ui->spYear->setValue(dt.date().year() - 2000);
|
||||
|
||||
blockSignals(false);
|
||||
m_ui->spHour->setValue(dt.time().hour());
|
||||
m_ui->spMinutes->setValue(dt.time().minute());
|
||||
m_ui->spSeconds->setValue(dt.time().second());
|
||||
|
||||
const QDateTime dtNew = dateTime();
|
||||
if (dtNew != oldDateTime)
|
||||
emit dateTimeChanged();
|
||||
blockSignals(false);
|
||||
|
||||
const QDateTime dtNew = dateTime();
|
||||
if (dtNew != oldDateTime)
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
|
||||
|
||||
void LtsDateTimeEdit::onDateTimeChanged()
|
||||
{
|
||||
emit dateTimeChanged();
|
||||
emit dateTimeChanged();
|
||||
|
||||
QDateTime dateTime;
|
||||
dateTime = dateTime.addYears(m_ui->spYear->value());
|
||||
dateTime = dateTime.addMonths(m_ui->cbxMonth->currentData().toInt());
|
||||
dateTime = dateTime.addDays(m_ui->spDay->value());
|
||||
dateTime = dateTime.addSecs(m_ui->spHour->value()*60*60 + m_ui->spMinutes->value()*60 + m_ui->spSeconds->value());
|
||||
if (dateTime.isValid())
|
||||
{
|
||||
m_dateTime = dateTime;
|
||||
|
||||
}
|
||||
QDateTime dateTime;
|
||||
dateTime = dateTime.addYears(m_ui->spYear->value());
|
||||
dateTime = dateTime.addMonths(m_ui->cbxMonth->currentData().toInt());
|
||||
dateTime = dateTime.addDays(m_ui->spDay->value());
|
||||
dateTime =
|
||||
dateTime.addSecs(m_ui->spHour->value() * 60 * 60 + m_ui->spMinutes->value() * 60 + m_ui->spSeconds->value());
|
||||
if (dateTime.isValid())
|
||||
{
|
||||
m_dateTime = dateTime;
|
||||
}
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::onTimeZoneChanged()
|
||||
{
|
||||
if (m_ui->cbxMonth->currentText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
QChar tz = m_ui->cbxTimeZone->currentText().at(0);
|
||||
if (tz.isLower())
|
||||
tz = tz.toUpper();
|
||||
if (tz.toLatin1() == 'J')
|
||||
tz = QLatin1Char('Z');
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findData(tz));
|
||||
int offset = DTG::timezone2Secs(tz.toLatin1());
|
||||
if (offset != m_tzOffset)
|
||||
{
|
||||
const auto ms = msecsSinceEpoch();
|
||||
m_tzOffset = offset;
|
||||
setMsecsSinceEpoch(ms+m_tzOffset);
|
||||
}
|
||||
if (m_ui->cbxMonth->currentText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
QChar tz = m_ui->cbxTimeZone->currentText().at(0);
|
||||
if (tz.isLower())
|
||||
tz = tz.toUpper();
|
||||
if (tz.toLatin1() == 'J')
|
||||
tz = QLatin1Char('Z');
|
||||
m_ui->cbxTimeZone->setCurrentIndex(m_ui->cbxTimeZone->findData(tz));
|
||||
int offset = DTG::timezone2Secs(tz.toLatin1());
|
||||
if (offset != m_tzOffset)
|
||||
{
|
||||
const auto ms = msecsSinceEpoch();
|
||||
m_tzOffset = offset;
|
||||
setMsecsSinceEpoch(ms + m_tzOffset);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::onMonthChanged(int month)
|
||||
{
|
||||
|
||||
Q_UNUSED(month);
|
||||
|
||||
Q_UNUSED(month);
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setWithCheckBox(bool checkBoxEnabled)
|
||||
{
|
||||
if (m_withCheckBox == checkBoxEnabled)
|
||||
return;
|
||||
if (m_withCheckBox == checkBoxEnabled)
|
||||
return;
|
||||
|
||||
m_withCheckBox = checkBoxEnabled;
|
||||
m_ui->checkBox->setVisible(m_withCheckBox);
|
||||
if (!m_withCheckBox)
|
||||
m_ui->checkBox->setChecked(true);
|
||||
emit withCheckBoxChanged(m_withCheckBox);
|
||||
m_withCheckBox = checkBoxEnabled;
|
||||
m_ui->checkBox->setVisible(m_withCheckBox);
|
||||
if (!m_withCheckBox)
|
||||
m_ui->checkBox->setChecked(true);
|
||||
emit withCheckBoxChanged(m_withCheckBox);
|
||||
}
|
||||
|
||||
bool LtsDateTimeEdit::isCheckBoxChecked() const
|
||||
{
|
||||
return m_ui->checkBox->isChecked();
|
||||
return m_ui->checkBox->isChecked();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setWithNowButton(bool nowButton)
|
||||
{
|
||||
if (m_withNowButton == nowButton)
|
||||
return;
|
||||
if (m_withNowButton == nowButton)
|
||||
return;
|
||||
|
||||
m_withNowButton = nowButton;
|
||||
m_ui->pbNow->setVisible(m_withNowButton);
|
||||
emit withNowButtonChanged(m_withNowButton);
|
||||
m_withNowButton = nowButton;
|
||||
m_ui->pbNow->setVisible(m_withNowButton);
|
||||
emit withNowButtonChanged(m_withNowButton);
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::onCheckBoxChanged(bool checked)
|
||||
{
|
||||
m_ui->spDay->setEnabled(checked);
|
||||
m_ui->spHour->setEnabled(checked);
|
||||
m_ui->spMinutes->setEnabled(checked);
|
||||
m_ui->spSeconds->setEnabled(checked);
|
||||
m_ui->spYear->setEnabled(checked);
|
||||
m_ui->cbxMonth->setEnabled(checked);
|
||||
m_ui->cbxTimeZone->setEnabled(checked);
|
||||
m_ui->pbNow->setEnabled(checked);
|
||||
emit dateTimeChanged();
|
||||
m_ui->spDay->setEnabled(checked);
|
||||
m_ui->spHour->setEnabled(checked);
|
||||
m_ui->spMinutes->setEnabled(checked);
|
||||
m_ui->spSeconds->setEnabled(checked);
|
||||
m_ui->spYear->setEnabled(checked);
|
||||
m_ui->cbxMonth->setEnabled(checked);
|
||||
m_ui->cbxTimeZone->setEnabled(checked);
|
||||
m_ui->pbNow->setEnabled(checked);
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setMsecsSinceEpoch(qint64 mSecsSinceEpoch)
|
||||
{
|
||||
if (mSecsSinceEpoch == 0 && m_withCheckBox)
|
||||
{
|
||||
m_ui->checkBox->setChecked(false);
|
||||
return;
|
||||
}
|
||||
m_ui->checkBox->setChecked(true);
|
||||
setDateTime(QDateTime::fromMSecsSinceEpoch(mSecsSinceEpoch).toUTC());
|
||||
if (mSecsSinceEpoch == 0 && m_withCheckBox)
|
||||
{
|
||||
m_ui->checkBox->setChecked(false);
|
||||
return;
|
||||
}
|
||||
m_ui->checkBox->setChecked(true);
|
||||
setDateTime(QDateTime::fromMSecsSinceEpoch(mSecsSinceEpoch).toUTC());
|
||||
}
|
||||
|
||||
qint64 LtsDateTimeEdit::msecsSinceEpoch() const
|
||||
{
|
||||
const QDateTime dt(dateTime());
|
||||
if (dt.isNull())
|
||||
return 0;
|
||||
return dt.toMSecsSinceEpoch();
|
||||
const QDateTime dt(dateTime());
|
||||
if (dt.isNull())
|
||||
return 0;
|
||||
return dt.toMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::clear()
|
||||
{
|
||||
m_ui->spDay->clear();
|
||||
m_ui->spHour->clear();
|
||||
m_ui->spMinutes->clear();
|
||||
m_ui->spSeconds->clear();
|
||||
m_ui->spYear->clear();
|
||||
emit dateTimeChanged();
|
||||
m_ui->spDay->clear();
|
||||
m_ui->spHour->clear();
|
||||
m_ui->spMinutes->clear();
|
||||
m_ui->spSeconds->clear();
|
||||
m_ui->spYear->clear();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setCheckBoxChecked(bool bChecked)
|
||||
{
|
||||
m_ui->checkBox->setChecked(bChecked);
|
||||
m_ui->checkBox->setChecked(bChecked);
|
||||
}
|
||||
|
||||
QDateTime LtsDateTimeEdit::dateTime() const
|
||||
{
|
||||
if (!m_ui->checkBox->isChecked())
|
||||
return QDateTime();
|
||||
if (!m_ui->checkBox->isChecked())
|
||||
return QDateTime();
|
||||
|
||||
QDateTime final;
|
||||
int year = 0;
|
||||
if (m_ui->spYear->value() < 1000)
|
||||
{
|
||||
year=m_ui->spYear->value()+2000;
|
||||
}
|
||||
else
|
||||
{
|
||||
year=m_ui->spYear->value();
|
||||
}
|
||||
QDate date(year,m_ui->cbxMonth->currentData().toInt(), m_ui->spDay->value());
|
||||
final.setDate(date);
|
||||
final = final.addSecs(m_ui->spHour->value()*60*60 + m_ui->spMinutes->value()*60 + m_ui->spSeconds->value());
|
||||
QDateTime final;
|
||||
int year = 0;
|
||||
if (m_ui->spYear->value() < 1000)
|
||||
{
|
||||
year = m_ui->spYear->value() + 2000;
|
||||
}
|
||||
else
|
||||
{
|
||||
year = m_ui->spYear->value();
|
||||
}
|
||||
QDate date(year, m_ui->cbxMonth->currentData().toInt(), m_ui->spDay->value());
|
||||
final.setDate(date);
|
||||
final = final.addSecs(m_ui->spHour->value() * 60 * 60 + m_ui->spMinutes->value() * 60 + m_ui->spSeconds->value());
|
||||
|
||||
if (!final.isValid())
|
||||
return QDateTime();
|
||||
if (!final.isValid())
|
||||
return QDateTime();
|
||||
|
||||
|
||||
return QDateTime(final.date(), final.time(), Qt::OffsetFromUTC, m_tzOffset).toUTC();
|
||||
return QDateTime(final.date(), final.time(), Qt::OffsetFromUTC, m_tzOffset).toUTC();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setMaximumTimeMSec(qint64 msec)
|
||||
{
|
||||
const auto maximumDate(QDateTime::fromMSecsSinceEpoch(msec).date());
|
||||
m_ui->spYear->setMaximum(maximumDate.year()-2000);
|
||||
|
||||
|
||||
|
||||
|
||||
const auto maximumDate(QDateTime::fromMSecsSinceEpoch(msec).date());
|
||||
m_ui->spYear->setMaximum(maximumDate.year() - 2000);
|
||||
}
|
||||
|
||||
qint64 LtsDateTimeEdit::minimumTimeMSec() const
|
||||
{
|
||||
QDate date;
|
||||
date.setDate(m_ui->spYear->minimum(), m_maxMonth, m_ui->spMinutes->minimum() );
|
||||
return QDateTime(date).toMSecsSinceEpoch();
|
||||
QDate date;
|
||||
date.setDate(m_ui->spYear->minimum(), m_maxMonth, m_ui->spMinutes->minimum());
|
||||
return QDateTime(date).toMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setMinimumTimeMSec(qint64 msec)
|
||||
{
|
||||
const auto minimumDate(QDateTime::fromMSecsSinceEpoch(msec).date());
|
||||
|
||||
m_ui->spYear->setMinimum(minimumDate.year()-2000);
|
||||
|
||||
const auto minimumDate(QDateTime::fromMSecsSinceEpoch(msec).date());
|
||||
|
||||
m_ui->spYear->setMinimum(minimumDate.year() - 2000);
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setRetrieveCurrentTimeCallback(const CurrentTimeCallback &cb)
|
||||
void LtsDateTimeEdit::setRetrieveCurrentTimeCallback(const CurrentTimeCallback& cb)
|
||||
{
|
||||
m_getCurrentTimeCallback = cb;
|
||||
m_getCurrentTimeCallback = cb;
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::onSetFixedDateTime()
|
||||
{
|
||||
setMsecsSinceEpoch(LtsUtils::OperatorSettings::getInstance()->value(QStringLiteral("TimeSettings"), QStringLiteral("FixedTime"), 0).toLongLong());
|
||||
setMsecsSinceEpoch(LtsUtils::OperatorSettings::getInstance()
|
||||
->value(QStringLiteral("TimeSettings"), QStringLiteral("FixedTime"), 0)
|
||||
.toLongLong());
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::onSetOffsetDateTime()
|
||||
{
|
||||
if (!m_getCurrentTimeCallback)
|
||||
return;
|
||||
qint64 offset = LtsUtils::OperatorSettings::getInstance()->value(QStringLiteral("TimeSettings"), QStringLiteral("Offset"), 0).toLongLong();
|
||||
|
||||
setMsecsSinceEpoch((m_getCurrentTimeCallback() / 1000) * 1000 + offset);
|
||||
}
|
||||
if (!m_getCurrentTimeCallback)
|
||||
return;
|
||||
qint64 offset = LtsUtils::OperatorSettings::getInstance()
|
||||
->value(QStringLiteral("TimeSettings"), QStringLiteral("Offset"), 0)
|
||||
.toLongLong();
|
||||
|
||||
setMsecsSinceEpoch((m_getCurrentTimeCallback() / 1000) * 1000 + offset);
|
||||
}
|
||||
|
||||
void LtsDateTimeEdit::setSubWidgetsProperties(QString name, QVariant value)
|
||||
{
|
||||
m_ui->spDay->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spHour->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spMinutes->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spSeconds->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spYear->setProperty(name.toStdString().c_str(), value);
|
||||
|
||||
m_ui->spDay->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spHour->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spMinutes->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spSeconds->setProperty(name.toStdString().c_str(), value);
|
||||
m_ui->spYear->setProperty(name.toStdString().c_str(), value);
|
||||
}
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+138
-89
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
@@ -23,119 +21,170 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsDateTimeEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool withCheckBox READ withCheckBox WRITE setWithCheckBox)
|
||||
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
||||
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
||||
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
||||
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
||||
Q_PROPERTY(bool withCheckBox READ withCheckBox WRITE setWithCheckBox)
|
||||
|
||||
public:
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
explicit LtsDateTimeEdit(QWidget *parent = nullptr, bool withNowButton = true, bool withCheckBox = false);
|
||||
~LtsDateTimeEdit();
|
||||
public:
|
||||
using CurrentTimeCallback = std::function<qint64()>;
|
||||
explicit LtsDateTimeEdit(QWidget* parent = nullptr, bool withNowButton = true, bool withCheckBox = false);
|
||||
~LtsDateTimeEdit();
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
bool isEmpty() const { return msecsSinceEpoch() == 0; }
|
||||
qint64 msecsSinceEpoch() const;
|
||||
|
||||
void setAutoForward(const bool af) { m_autoForward = af; }
|
||||
bool getAutoForward() const { return m_autoForward; }
|
||||
bool isEmpty() const
|
||||
{
|
||||
return msecsSinceEpoch() == 0;
|
||||
}
|
||||
|
||||
void setEditTimezone(const bool edit) { m_editTimezone = edit; }
|
||||
bool getEditTimezone() const { return m_editTimezone; }
|
||||
void setAutoForward(const bool af)
|
||||
{
|
||||
m_autoForward = af;
|
||||
}
|
||||
|
||||
void setWithButtons(const bool buttons) { m_withButtons = buttons; }
|
||||
bool getWithButtons() const { return m_withButtons; }
|
||||
bool getAutoForward() const
|
||||
{
|
||||
return m_autoForward;
|
||||
}
|
||||
|
||||
void setWithSlider(const bool slider) { m_withSlider = slider; }
|
||||
bool getWithSlider() const { return m_withSlider; }
|
||||
void setEditTimezone(const bool edit)
|
||||
{
|
||||
m_editTimezone = edit;
|
||||
}
|
||||
|
||||
void setReadOnly(const bool readOnly) { m_readOnly = readOnly; }
|
||||
bool isReadOnly() const { return m_readOnly; }
|
||||
bool getEditTimezone() const
|
||||
{
|
||||
return m_editTimezone;
|
||||
}
|
||||
|
||||
bool withCheckBox() const { return m_withCheckBox; }
|
||||
void setCheckBoxChecked(bool bChecked);
|
||||
bool isCheckBoxChecked() const;
|
||||
void setWithButtons(const bool buttons)
|
||||
{
|
||||
m_withButtons = buttons;
|
||||
}
|
||||
|
||||
bool withNowButton() const { return m_withNowButton; }
|
||||
void setDateTime(const QDateTime &datetime);
|
||||
bool getWithButtons() const
|
||||
{
|
||||
return m_withButtons;
|
||||
}
|
||||
|
||||
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
qint64 minimumTimeMSec() const;
|
||||
void setWithSlider(const bool slider)
|
||||
{
|
||||
m_withSlider = slider;
|
||||
}
|
||||
|
||||
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
qint64 maximumTimeMSec() const { return m_maxTimeMSec; };
|
||||
bool getWithSlider() const
|
||||
{
|
||||
return m_withSlider;
|
||||
}
|
||||
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max) { setMinimumTimeMSec(min); setMaximumTimeMSec(max); }
|
||||
void setReadOnly(const bool readOnly)
|
||||
{
|
||||
m_readOnly = readOnly;
|
||||
}
|
||||
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback &cb);
|
||||
void updateDateTimeType();
|
||||
bool isReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
bool withCheckBox() const
|
||||
{
|
||||
return m_withCheckBox;
|
||||
}
|
||||
|
||||
void setCheckBoxChecked(bool bChecked);
|
||||
bool isCheckBoxChecked() const;
|
||||
|
||||
void setSubWidgetsProperties(QString name, QVariant value);
|
||||
bool withNowButton() const
|
||||
{
|
||||
return m_withNowButton;
|
||||
}
|
||||
|
||||
bool isValidDate() const
|
||||
{
|
||||
|
||||
return m_dateTime.isValid();
|
||||
}
|
||||
void setDateTime(const QDateTime& datetime);
|
||||
|
||||
private:
|
||||
QDateTime dateTime() const;
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
void setMinimumTimeMSec(qint64 msec);
|
||||
qint64 minimumTimeMSec() const;
|
||||
|
||||
public slots:
|
||||
void setWithCheckBox(bool checkBoxEnabled);
|
||||
void setWithNowButton(bool nowButton);
|
||||
void setMsecsSinceEpoch(qint64 mSecsSinceEpoch);
|
||||
void clear();
|
||||
void setMaximumTimeMSec(qint64 msec);
|
||||
|
||||
void onSetFixedDateTime();
|
||||
void onSetOffsetDateTime();
|
||||
qint64 maximumTimeMSec() const
|
||||
{
|
||||
return m_maxTimeMSec;
|
||||
};
|
||||
|
||||
public slots:
|
||||
void onDateTimeChanged();
|
||||
void setMinMaxTimeMSec(qint64 min, qint64 max)
|
||||
{
|
||||
setMinimumTimeMSec(min);
|
||||
setMaximumTimeMSec(max);
|
||||
}
|
||||
|
||||
signals:
|
||||
void dateTimeChanged();
|
||||
void withCheckBoxChanged(bool checkBoxEnabled);
|
||||
void withNowButtonChanged(bool nowButton);
|
||||
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback& cb);
|
||||
void updateDateTimeType();
|
||||
|
||||
private slots:
|
||||
void onCheckBoxChanged(bool checked);
|
||||
void onTimeZoneChanged();
|
||||
void onMonthChanged(int month);
|
||||
bool setTimezone(char tz);
|
||||
char getTimezone() const;
|
||||
|
||||
private:
|
||||
void setSubWidgetsProperties(QString name, QVariant value);
|
||||
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
qint64 m_curTimeMSec = -1;
|
||||
bool isValidDate() const
|
||||
{
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_withCheckBox = false;
|
||||
bool m_withNowButton = false;
|
||||
return m_dateTime.isValid();
|
||||
}
|
||||
|
||||
int m_tzOffset;
|
||||
int m_minMonth;
|
||||
int m_maxMonth;
|
||||
QShortcut *m_scFixed;
|
||||
QShortcut *m_scOffset;
|
||||
QDateTime m_dateTime;
|
||||
CurrentTimeCallback m_getCurrentTimeCallback;
|
||||
Ui::LtsDateTimeEdit *m_ui;
|
||||
private:
|
||||
QDateTime dateTime() const;
|
||||
void setMinMaxMonth(int minMonth, int maxMonth);
|
||||
|
||||
public slots:
|
||||
void setWithCheckBox(bool checkBoxEnabled);
|
||||
void setWithNowButton(bool nowButton);
|
||||
void setMsecsSinceEpoch(qint64 mSecsSinceEpoch);
|
||||
void clear();
|
||||
|
||||
void onSetFixedDateTime();
|
||||
void onSetOffsetDateTime();
|
||||
|
||||
public slots:
|
||||
void onDateTimeChanged();
|
||||
|
||||
signals:
|
||||
void dateTimeChanged();
|
||||
void withCheckBoxChanged(bool checkBoxEnabled);
|
||||
void withNowButtonChanged(bool nowButton);
|
||||
|
||||
private slots:
|
||||
void onCheckBoxChanged(bool checked);
|
||||
void onTimeZoneChanged();
|
||||
void onMonthChanged(int month);
|
||||
|
||||
private:
|
||||
qint64 m_minTimeMSec = 0;
|
||||
qint64 m_maxTimeMSec = 0;
|
||||
qint64 m_curTimeMSec = -1;
|
||||
|
||||
bool m_editTimezone = true;
|
||||
bool m_autoForward = true;
|
||||
bool m_withButtons = false;
|
||||
bool m_withSlider = false;
|
||||
bool m_readOnly = false;
|
||||
bool m_withCheckBox = false;
|
||||
bool m_withNowButton = false;
|
||||
|
||||
int m_tzOffset;
|
||||
int m_minMonth;
|
||||
int m_maxMonth;
|
||||
QShortcut* m_scFixed;
|
||||
QShortcut* m_scOffset;
|
||||
QDateTime m_dateTime;
|
||||
CurrentTimeCallback m_getCurrentTimeCallback;
|
||||
Ui::LtsDateTimeEdit* m_ui;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+127
-145
@@ -1,217 +1,199 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_dialog_button_box.h"
|
||||
#include "ui_lts_dialog_button_box.h"
|
||||
|
||||
#include "lts_message_dialog.h"
|
||||
#include "ui_lts_dialog_button_box.h"
|
||||
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <QMenu>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsDialogButtonBox::LtsDialogButtonBox(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_isTablet(LtsSessionData::LtsSessionData::getInstance()->isTablet())
|
||||
, m_ui(new Ui::LtsDialogButtonBox)
|
||||
LtsDialogButtonBox::LtsDialogButtonBox(QWidget* parent)
|
||||
: QWidget(parent), m_isTablet(LtsSessionData::LtsSessionData::getInstance()->isTablet()),
|
||||
m_ui(new Ui::LtsDialogButtonBox)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
_setVisibilityForAll(false);
|
||||
m_ui->setupUi(this);
|
||||
_setVisibilityForAll(false);
|
||||
|
||||
|
||||
QMenu *libraryMenu = new QMenu(m_ui->pbLibrary);
|
||||
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_load.svg")),
|
||||
tr("Load"), this, &LtsDialogButtonBox::signalLibraryLoadClicked);
|
||||
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_save.svg")),
|
||||
tr("Save"), this, &LtsDialogButtonBox::signalLibrarySaveClicked);
|
||||
m_ui->pbLibrary->setMenu(libraryMenu);
|
||||
QMenu* libraryMenu = new QMenu(m_ui->pbLibrary);
|
||||
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_load.svg")), tr("Load"), this,
|
||||
&LtsDialogButtonBox::signalLibraryLoadClicked);
|
||||
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_save.svg")), tr("Save"), this,
|
||||
&LtsDialogButtonBox::signalLibrarySaveClicked);
|
||||
m_ui->pbLibrary->setMenu(libraryMenu);
|
||||
|
||||
|
||||
m_ui->pbOk->setVisible(true);
|
||||
m_ui->pbClose->setVisible(true);
|
||||
|
||||
m_ui->pbOk->setVisible(true);
|
||||
m_ui->pbClose->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
LtsDialogButtonBox::~LtsDialogButtonBox()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::_setVisibilityForAll(bool visible)
|
||||
{
|
||||
const auto buttons = findChildren<QPushButton *>();
|
||||
for (QPushButton *button : buttons)
|
||||
button->setVisible(visible);
|
||||
const auto buttons = findChildren<QPushButton*>();
|
||||
for (QPushButton* button : buttons)
|
||||
button->setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setText(DialogButton button, const QString &text)
|
||||
void LtsDialogButtonBox::setText(DialogButton button, const QString& text)
|
||||
{
|
||||
|
||||
|
||||
QPushButton *btn = getButton(button);
|
||||
QPushButton* btn = getButton(button);
|
||||
|
||||
if (btn)
|
||||
btn->setText(text);
|
||||
if (btn)
|
||||
btn->setText(text);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setToolTip(DialogButton button, const QString &text)
|
||||
void LtsDialogButtonBox::setToolTip(DialogButton button, const QString& text)
|
||||
{
|
||||
QPushButton *btn = getButton(button);
|
||||
QPushButton* btn = getButton(button);
|
||||
|
||||
if (btn)
|
||||
btn->setToolTip(text);
|
||||
if (btn)
|
||||
btn->setToolTip(text);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setIcon(DialogButton button, const QIcon &icon)
|
||||
void LtsDialogButtonBox::setIcon(DialogButton button, const QIcon& icon)
|
||||
{
|
||||
QPushButton *btn = getButton(button);
|
||||
QPushButton* btn = getButton(button);
|
||||
|
||||
if (btn)
|
||||
btn->setIcon(icon);
|
||||
if (btn)
|
||||
btn->setIcon(icon);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setMenu(DialogButton button, QMenu *menu)
|
||||
void LtsDialogButtonBox::setMenu(DialogButton button, QMenu* menu)
|
||||
{
|
||||
QPushButton *btn = getButton(button);
|
||||
QPushButton* btn = getButton(button);
|
||||
|
||||
if (btn)
|
||||
btn->setMenu(menu);
|
||||
if (btn)
|
||||
btn->setMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
QPushButton *LtsDialogButtonBox::getButton(DialogButton button) const
|
||||
QPushButton* LtsDialogButtonBox::getButton(DialogButton button) const
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case DialogButton::ReadOnly:
|
||||
return m_ui->pbReadOnly;
|
||||
case DialogButton::Ok:
|
||||
return m_ui->pbOk;
|
||||
case DialogButton::Apply:
|
||||
return m_ui->pbApply;
|
||||
case DialogButton::Close:
|
||||
return m_ui->pbClose;
|
||||
case DialogButton::Yes:
|
||||
return m_ui->pbYes;
|
||||
case DialogButton::No:
|
||||
return m_ui->pbNo;
|
||||
case DialogButton::Remove:
|
||||
return m_ui->pbRemove;
|
||||
case DialogButton::Hide:
|
||||
return m_ui->pbHide;
|
||||
case DialogButton::Add:
|
||||
return m_ui->pbAdd;
|
||||
case DialogButton::Help:
|
||||
return m_ui->pbHelp;
|
||||
case DialogButton::Edit:
|
||||
return m_ui->pbEdit;
|
||||
case DialogButton::Save:
|
||||
return m_ui->pbSave;
|
||||
case DialogButton::Load:
|
||||
return m_ui->pbLoad;
|
||||
case DialogButton::Show:
|
||||
return m_ui->pbShow;
|
||||
case DialogButton::Import:
|
||||
return m_ui->pbImport;
|
||||
case DialogButton::Export:
|
||||
return m_ui->pbExport;
|
||||
case DialogButton::Library:
|
||||
return m_ui->pbLibrary;
|
||||
case DialogButton::CenterMap:
|
||||
return m_ui->pbCenterMap;
|
||||
case DialogButton::ZoomMapTo:
|
||||
return m_ui->pbZoomMapTo;
|
||||
case DialogButton::Print:
|
||||
return m_ui->pbPrint;
|
||||
switch (button)
|
||||
{
|
||||
case DialogButton::ReadOnly:
|
||||
return m_ui->pbReadOnly;
|
||||
case DialogButton::Ok:
|
||||
return m_ui->pbOk;
|
||||
case DialogButton::Apply:
|
||||
return m_ui->pbApply;
|
||||
case DialogButton::Close:
|
||||
return m_ui->pbClose;
|
||||
case DialogButton::Yes:
|
||||
return m_ui->pbYes;
|
||||
case DialogButton::No:
|
||||
return m_ui->pbNo;
|
||||
case DialogButton::Remove:
|
||||
return m_ui->pbRemove;
|
||||
case DialogButton::Hide:
|
||||
return m_ui->pbHide;
|
||||
case DialogButton::Add:
|
||||
return m_ui->pbAdd;
|
||||
case DialogButton::Help:
|
||||
return m_ui->pbHelp;
|
||||
case DialogButton::Edit:
|
||||
return m_ui->pbEdit;
|
||||
case DialogButton::Save:
|
||||
return m_ui->pbSave;
|
||||
case DialogButton::Load:
|
||||
return m_ui->pbLoad;
|
||||
case DialogButton::Show:
|
||||
return m_ui->pbShow;
|
||||
case DialogButton::Import:
|
||||
return m_ui->pbImport;
|
||||
case DialogButton::Export:
|
||||
return m_ui->pbExport;
|
||||
case DialogButton::Library:
|
||||
return m_ui->pbLibrary;
|
||||
case DialogButton::CenterMap:
|
||||
return m_ui->pbCenterMap;
|
||||
case DialogButton::ZoomMapTo:
|
||||
return m_ui->pbZoomMapTo;
|
||||
case DialogButton::Print:
|
||||
return m_ui->pbPrint;
|
||||
#ifdef LTS_DEBUG
|
||||
case DialogButton::_debug_:
|
||||
return m_ui->_pbChanges;
|
||||
case DialogButton::_debug_:
|
||||
return m_ui->_pbChanges;
|
||||
#endif
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return nullptr;
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::slotRemoveClicked()
|
||||
{
|
||||
if (LtsMessageDialog::showMessage(this,
|
||||
tr("Are you sure you want to delete the selected entry(ies)?"),
|
||||
tr("Remove selected entry(ies)"),
|
||||
Behaviour::Modal,
|
||||
Button::Yes | Button::No)
|
||||
== Button::Yes)
|
||||
emit signalRemoveClicked();
|
||||
if (LtsMessageDialog::showMessage(this, tr("Are you sure you want to delete the selected entry(ies)?"),
|
||||
tr("Remove selected entry(ies)"), Behaviour::Modal,
|
||||
Button::Yes | Button::No) == Button::Yes)
|
||||
emit signalRemoveClicked();
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setButtonsVisible(QPushButton *pb)
|
||||
void LtsDialogButtonBox::setButtonsVisible(QPushButton* pb)
|
||||
{
|
||||
if (!pb || (pb == m_ui->pbPrint && m_isTablet))
|
||||
return;
|
||||
m_ui->line->setVisible(true);
|
||||
pb->setVisible(true);
|
||||
if (!pb || (pb == m_ui->pbPrint && m_isTablet))
|
||||
return;
|
||||
m_ui->line->setVisible(true);
|
||||
pb->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setButtonVisible(DialogButton button, bool visible)
|
||||
{
|
||||
QPushButton *pb = getButton(button);
|
||||
if (!pb)
|
||||
return;
|
||||
if (m_isTablet && pb == m_ui->pbPrint)
|
||||
{
|
||||
pb->setVisible(false);
|
||||
return;
|
||||
}
|
||||
pb->setVisible(visible);
|
||||
QPushButton* pb = getButton(button);
|
||||
if (!pb)
|
||||
return;
|
||||
if (m_isTablet && pb == m_ui->pbPrint)
|
||||
{
|
||||
pb->setVisible(false);
|
||||
return;
|
||||
}
|
||||
pb->setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
bool LtsDialogButtonBox::isButtonVisible(DialogButton button) const
|
||||
{
|
||||
const QPushButton *pb = getButton(button);
|
||||
return (pb ? pb->isVisible() : false);
|
||||
const QPushButton* pb = getButton(button);
|
||||
return (pb ? pb->isVisible() : false);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogButtonBox::setButtonEnabled(DialogButton button, bool enabled)
|
||||
{
|
||||
QPushButton *pb = getButton(button);
|
||||
QPushButton* pb = getButton(button);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case DialogButton::Close:
|
||||
case DialogButton::Ok:
|
||||
case DialogButton::Apply:
|
||||
|
||||
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case DialogButton::Close:
|
||||
case DialogButton::Ok:
|
||||
case DialogButton::Apply:
|
||||
|
||||
{
|
||||
#ifdef LTS_DEBUG
|
||||
LtsMessageDialog::showMessage(this, QStringLiteral("Hier stimmt etwas nicht. Bitte MIKE bescheid geben WAS geklickt oder gemacht wurde als dieser Dialog auftauchte, damit ich es fixen kann. Danke."), QStringLiteral(">>> STOP <<<"));
|
||||
LtsMessageDialog::showMessage(
|
||||
this,
|
||||
QStringLiteral("Hier stimmt etwas nicht. Bitte MIKE bescheid geben WAS geklickt oder gemacht wurde als "
|
||||
"dieser Dialog auftauchte, damit ich es fixen kann. Danke."),
|
||||
QStringLiteral(">>> STOP <<<"));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pb)
|
||||
pb->setEnabled(enabled);
|
||||
if (pb)
|
||||
pb->setEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
bool LtsDialogButtonBox::isButtonEnabled(DialogButton button) const
|
||||
{
|
||||
auto *that = const_cast<LtsDialogButtonBox *>(this);
|
||||
const QPushButton *pb = that->getButton(button);
|
||||
return (pb ? pb->isEnabled() : false);
|
||||
auto* that = const_cast<LtsDialogButtonBox*>(this);
|
||||
const QPushButton* pb = that->getButton(button);
|
||||
return (pb ? pb->isEnabled() : false);
|
||||
}
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+128
-152
@@ -1,14 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
#include "lts_message_dialog.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@@ -17,181 +15,159 @@ class LtsDialogButtonBox;
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
enum class DialogButton
|
||||
{
|
||||
|
||||
ReadOnly,
|
||||
Ok,
|
||||
Apply,
|
||||
Close,
|
||||
Yes,
|
||||
No,
|
||||
enum class DialogButton {
|
||||
|
||||
|
||||
Remove,
|
||||
Hide,
|
||||
Add,
|
||||
Help,
|
||||
Edit,
|
||||
Save,
|
||||
Load,
|
||||
Show,
|
||||
Import,
|
||||
Export,
|
||||
CenterMap,
|
||||
ZoomMapTo,
|
||||
Library,
|
||||
Print,
|
||||
ReadOnly,
|
||||
Ok,
|
||||
Apply,
|
||||
Close,
|
||||
Yes,
|
||||
No,
|
||||
|
||||
Remove,
|
||||
Hide,
|
||||
Add,
|
||||
Help,
|
||||
Edit,
|
||||
Save,
|
||||
Load,
|
||||
Show,
|
||||
Import,
|
||||
Export,
|
||||
CenterMap,
|
||||
ZoomMapTo,
|
||||
Library,
|
||||
Print,
|
||||
|
||||
#ifdef LTS_DEBUG
|
||||
_debug_,
|
||||
_debug_,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsDialogButtonBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsDialogButtonBox(QWidget *parent);
|
||||
~LtsDialogButtonBox();
|
||||
public:
|
||||
explicit LtsDialogButtonBox(QWidget* parent);
|
||||
~LtsDialogButtonBox();
|
||||
|
||||
|
||||
|
||||
template <typename Func2>
|
||||
void connectButton(DialogButton button, const typename QtPrivate::FunctionPointer<Func2>::Object *receiver,
|
||||
Func2 slot, Qt::ConnectionType type = Qt::AutoConnection)
|
||||
{
|
||||
|
||||
template <typename Func2>
|
||||
void connectButton(DialogButton button, const typename QtPrivate::FunctionPointer<Func2>::Object* receiver,
|
||||
Func2 slot, Qt::ConnectionType type = Qt::AutoConnection)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
#ifdef LTS_DEBUG
|
||||
case DialogButton::_debug_:
|
||||
case DialogButton::_debug_:
|
||||
#endif
|
||||
case DialogButton::Close:
|
||||
case DialogButton::Ok:
|
||||
case DialogButton::ReadOnly:
|
||||
case DialogButton::Apply:
|
||||
case DialogButton::Help:
|
||||
{
|
||||
LtsMessageDialog::showMessage(this,
|
||||
QStringLiteral("Bitte den fuer das Plugin verantwortlichen kontaktieren:<br />"
|
||||
"m_buttonBox nicht mit Ok, Apply, Help, _debug_ oder Close verbinden<br />"
|
||||
"Note: Bitte nur m_buttonBox verwenden, keine LtsDialogButtonBox selber erstellen"
|
||||
"Ok & Apply werden automatisch zur virtual Methode 'apply()' im LtsDialog weitergeleitet.<br />"
|
||||
"Close schließt einfach den Dialog - im Destruktor oder in 'aboutToClose()' ist der 'Close Code' gut aufgehoben.<br />"
|
||||
"<br />"
|
||||
"FIXEN !!!!!"),
|
||||
QStringLiteral("--- STOP --- !!! FIXEN !!! ---"));
|
||||
break;
|
||||
}
|
||||
case DialogButton::Close:
|
||||
case DialogButton::Ok:
|
||||
case DialogButton::ReadOnly:
|
||||
case DialogButton::Apply:
|
||||
case DialogButton::Help: {
|
||||
LtsMessageDialog::showMessage(
|
||||
this,
|
||||
QStringLiteral(
|
||||
"Bitte den fuer das Plugin verantwortlichen kontaktieren:<br />"
|
||||
"m_buttonBox nicht mit Ok, Apply, Help, _debug_ oder Close verbinden<br />"
|
||||
"Note: Bitte nur m_buttonBox verwenden, keine LtsDialogButtonBox selber erstellen"
|
||||
"Ok & Apply werden automatisch zur virtual Methode 'apply()' im LtsDialog "
|
||||
"weitergeleitet.<br />"
|
||||
"Close schließt einfach den Dialog - im Destruktor oder in 'aboutToClose()' ist der 'Close "
|
||||
"Code' gut aufgehoben.<br />"
|
||||
"<br />"
|
||||
"FIXEN !!!!!"),
|
||||
QStringLiteral("--- STOP --- !!! FIXEN !!! ---"));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QPushButton* theSender = getButton(button);
|
||||
|
||||
if (!theSender)
|
||||
return;
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case DialogButton::Remove: {
|
||||
connect(this, &LtsDialogButtonBox::signalRemoveClicked, receiver, slot, type);
|
||||
connect(theSender, &QPushButton::clicked, this, &LtsDialogButtonBox::slotRemoveClicked);
|
||||
|
||||
break;
|
||||
}
|
||||
case DialogButton::Export:
|
||||
case DialogButton::Import: {
|
||||
if (m_isTablet)
|
||||
{
|
||||
theSender->setVisible(false);
|
||||
return;
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
}
|
||||
default:
|
||||
connect(theSender, &QPushButton::clicked, receiver, slot, type);
|
||||
break;
|
||||
}
|
||||
|
||||
setButtonsVisible(theSender);
|
||||
}
|
||||
|
||||
|
||||
QPushButton *theSender = getButton(button);
|
||||
|
||||
if (!theSender)
|
||||
return;
|
||||
|
||||
|
||||
switch (button)
|
||||
template <typename Func1, typename Func2>
|
||||
bool connectLibraryButton(const typename QtPrivate::FunctionPointer<Func2>::Object* receiver, Func1 slotLoad,
|
||||
Func2 slotSave, Qt::ConnectionType type = Qt::AutoConnection)
|
||||
{
|
||||
case DialogButton::Remove:
|
||||
{
|
||||
connect(this, &LtsDialogButtonBox::signalRemoveClicked, receiver, slot, type);
|
||||
connect(theSender, &QPushButton::clicked, this, &LtsDialogButtonBox::slotRemoveClicked);
|
||||
|
||||
break;
|
||||
}
|
||||
case DialogButton::Export:
|
||||
case DialogButton::Import:
|
||||
{
|
||||
if (m_isTablet)
|
||||
{
|
||||
theSender->setVisible(false);
|
||||
return;
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
}
|
||||
default:
|
||||
connect(theSender, &QPushButton::clicked, receiver, slot, type);
|
||||
break;
|
||||
QPushButton* theSender = getButton(DialogButton::Library);
|
||||
if (!theSender)
|
||||
return false;
|
||||
if (m_isTablet)
|
||||
{
|
||||
theSender->setVisible(false);
|
||||
return true;
|
||||
}
|
||||
setButtonsVisible(theSender);
|
||||
type = static_cast<Qt::ConnectionType>(type | Qt::UniqueConnection);
|
||||
return (connect(this, &LtsDialogButtonBox::signalLibraryLoadClicked, receiver, slotLoad, type) &&
|
||||
connect(this, &LtsDialogButtonBox::signalLibrarySaveClicked, receiver, slotSave, type));
|
||||
}
|
||||
|
||||
setButtonsVisible(theSender);
|
||||
}
|
||||
template <typename Func1, typename Func2>
|
||||
bool connectLibraryButton(const typename QtPrivate::FunctionPointer<Func2>::Object *receiver,
|
||||
Func1 slotLoad,
|
||||
Func2 slotSave,
|
||||
Qt::ConnectionType type = Qt::AutoConnection)
|
||||
{
|
||||
QPushButton *theSender = getButton(DialogButton::Library);
|
||||
if (!theSender)
|
||||
return false;
|
||||
if (m_isTablet)
|
||||
{
|
||||
theSender->setVisible(false);
|
||||
return true;
|
||||
}
|
||||
setButtonsVisible(theSender);
|
||||
type = static_cast<Qt::ConnectionType>(type | Qt::UniqueConnection);
|
||||
return (connect(this, &LtsDialogButtonBox::signalLibraryLoadClicked, receiver, slotLoad, type) &&
|
||||
connect(this, &LtsDialogButtonBox::signalLibrarySaveClicked, receiver, slotSave, type));
|
||||
}
|
||||
void setText(DialogButton button, const QString& text);
|
||||
|
||||
|
||||
void setToolTip(DialogButton button, const QString& text);
|
||||
void setIcon(DialogButton button, const QIcon& icon);
|
||||
void setMenu(DialogButton button, QMenu* menu);
|
||||
|
||||
void setText(DialogButton button, const QString &text);
|
||||
void setButtonEnabled(DialogButton button, bool enabled = true);
|
||||
bool isButtonEnabled(DialogButton button) const;
|
||||
|
||||
void setToolTip(DialogButton button, const QString &text);
|
||||
void setIcon(DialogButton button, const QIcon &icon);
|
||||
void setMenu(DialogButton button, QMenu *menu);
|
||||
void setButtonVisible(DialogButton button, bool visible = true);
|
||||
bool isButtonVisible(DialogButton button) const;
|
||||
|
||||
|
||||
QPushButton* getButton(DialogButton button) const;
|
||||
|
||||
void setButtonEnabled(DialogButton button, bool enabled = true);
|
||||
bool isButtonEnabled(DialogButton button) const;
|
||||
void _setVisibilityForAll(bool visible);
|
||||
|
||||
void setButtonVisible(DialogButton button, bool visible = true);
|
||||
bool isButtonVisible(DialogButton button) const;
|
||||
signals:
|
||||
void signalRemoveClicked();
|
||||
void signalHelpClicked();
|
||||
void signalLibraryLoadClicked();
|
||||
void signalLibrarySaveClicked();
|
||||
|
||||
|
||||
private slots:
|
||||
void slotRemoveClicked();
|
||||
|
||||
QPushButton *getButton(DialogButton button) const;
|
||||
private:
|
||||
const bool m_isTablet;
|
||||
|
||||
|
||||
void setButtonsVisible(QPushButton* pb);
|
||||
|
||||
void _setVisibilityForAll(bool visible);
|
||||
|
||||
signals:
|
||||
void signalRemoveClicked();
|
||||
void signalHelpClicked();
|
||||
void signalLibraryLoadClicked();
|
||||
void signalLibrarySaveClicked();
|
||||
|
||||
private slots:
|
||||
void slotRemoveClicked();
|
||||
|
||||
private:
|
||||
const bool m_isTablet;
|
||||
|
||||
|
||||
|
||||
void setButtonsVisible(QPushButton *pb);
|
||||
|
||||
Ui::LtsDialogButtonBox *m_ui;
|
||||
Ui::LtsDialogButtonBox* m_ui;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+85
-104
@@ -1,172 +1,153 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_dialog_helper.h"
|
||||
|
||||
#include "lts_dialog.h"
|
||||
#include "ui_lts_dialog_helper.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LDHScrollBar : public QScrollBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QScrollBar::QScrollBar;
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QScrollBar::QScrollBar;
|
||||
|
||||
void showEvent(QShowEvent *e) override
|
||||
{
|
||||
QScrollBar::showEvent(e);
|
||||
emit scrollbarVisiblityChanged(true);
|
||||
}
|
||||
void hideEvent(QHideEvent *e) override
|
||||
{
|
||||
QScrollBar::hideEvent(e);
|
||||
emit scrollbarVisiblityChanged(false);
|
||||
}
|
||||
Q_SIGNALS:
|
||||
void scrollbarVisiblityChanged(bool visible);
|
||||
void showEvent(QShowEvent* e) override
|
||||
{
|
||||
QScrollBar::showEvent(e);
|
||||
emit scrollbarVisiblityChanged(true);
|
||||
}
|
||||
|
||||
void hideEvent(QHideEvent* e) override
|
||||
{
|
||||
QScrollBar::hideEvent(e);
|
||||
emit scrollbarVisiblityChanged(false);
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void scrollbarVisiblityChanged(bool visible);
|
||||
};
|
||||
|
||||
|
||||
LtsDialogHelper::LtsDialogHelper(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::LtsDialogHelper())
|
||||
, m_dialog(nullptr)
|
||||
LtsDialogHelper::LtsDialogHelper(QWidget* parent) : QWidget(parent), m_ui(new Ui::LtsDialogHelper()), m_dialog(nullptr)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
auto hScroll = new LDHScrollBar(this);
|
||||
auto vScroll = new LDHScrollBar(this);
|
||||
m_ui->scrollArea->setHorizontalScrollBar(hScroll);
|
||||
m_ui->scrollArea->setVerticalScrollBar(vScroll);
|
||||
connect(hScroll, &LDHScrollBar::scrollbarVisiblityChanged,
|
||||
this, &LtsDialogHelper::onHScrollBarVisibilityChanged);
|
||||
connect(vScroll, &LDHScrollBar::scrollbarVisiblityChanged,
|
||||
this, &LtsDialogHelper::onVScrollBarVisibilityChanged);
|
||||
m_ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
auto hScroll = new LDHScrollBar(this);
|
||||
auto vScroll = new LDHScrollBar(this);
|
||||
m_ui->scrollArea->setHorizontalScrollBar(hScroll);
|
||||
m_ui->scrollArea->setVerticalScrollBar(vScroll);
|
||||
connect(hScroll, &LDHScrollBar::scrollbarVisiblityChanged, this, &LtsDialogHelper::onHScrollBarVisibilityChanged);
|
||||
connect(vScroll, &LDHScrollBar::scrollbarVisiblityChanged, this, &LtsDialogHelper::onVScrollBarVisibilityChanged);
|
||||
|
||||
#ifdef TABLET_MODE
|
||||
QList<QWidget *> scrollWidgets = findChildren<QWidget *>();
|
||||
QList<QWidget*> scrollWidgets = findChildren<QWidget*>();
|
||||
|
||||
for (auto i = scrollWidgets.begin(); i != scrollWidgets.end(); ++i)
|
||||
{
|
||||
QWidget *widget = *i;
|
||||
for (auto i = scrollWidgets.begin(); i != scrollWidgets.end(); ++i)
|
||||
{
|
||||
QWidget* widget = *i;
|
||||
|
||||
QVariant isConst = widget->property("const");
|
||||
if (isConst.isValid() && isConst.toBool())
|
||||
continue;
|
||||
QVariant isConst = widget->property("const");
|
||||
if (isConst.isValid() && isConst.toBool())
|
||||
continue;
|
||||
|
||||
LtsWidgets::addTouchScroll(widget);
|
||||
}
|
||||
LtsWidgets::addTouchScroll(widget);
|
||||
}
|
||||
#endif
|
||||
m_ui->buttonBox->setMinimumHeight(m_ui->buttonBox->sizeHint().height());
|
||||
}
|
||||
|
||||
|
||||
LtsDialogHelper::~LtsDialogHelper()
|
||||
{
|
||||
m_ui->scrollArea->horizontalScrollBar()->disconnect(this);
|
||||
m_ui->scrollArea->verticalScrollBar()->disconnect(this);
|
||||
delete m_ui;
|
||||
m_ui->scrollArea->horizontalScrollBar()->disconnect(this);
|
||||
m_ui->scrollArea->verticalScrollBar()->disconnect(this);
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
LtsDialogButtonBox *LtsDialogHelper::getButtonBox()
|
||||
LtsDialogButtonBox* LtsDialogHelper::getButtonBox()
|
||||
{
|
||||
return m_ui->buttonBox;
|
||||
return m_ui->buttonBox;
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogHelper::setDialog(LtsDialog *dialog)
|
||||
void LtsDialogHelper::setDialog(LtsDialog* dialog)
|
||||
{
|
||||
if (m_dialog != nullptr)
|
||||
return;
|
||||
if (m_dialog != nullptr)
|
||||
return;
|
||||
|
||||
m_dialog = dialog;
|
||||
m_dialog->setContentsMargins(QMargins());
|
||||
if (m_dialog->layout())
|
||||
m_dialog->layout()->setContentsMargins(QMargins());
|
||||
m_ui->scrollArea->setWidget(m_dialog);
|
||||
m_dialog = dialog;
|
||||
m_dialog->setContentsMargins(QMargins());
|
||||
if (m_dialog->layout())
|
||||
m_dialog->layout()->setContentsMargins(QMargins());
|
||||
m_ui->scrollArea->setWidget(m_dialog);
|
||||
|
||||
|
||||
{
|
||||
connect(dialog, &LtsDialog::destroyed, this, [this]()
|
||||
{
|
||||
m_dialog = nullptr;
|
||||
deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
connect(dialog, &LtsDialog::destroyed, this, [this]() {
|
||||
m_dialog = nullptr;
|
||||
deleteLater();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
LtsDialog *LtsDialogHelper::getDialog()
|
||||
LtsDialog* LtsDialogHelper::getDialog()
|
||||
{
|
||||
return m_dialog;
|
||||
return m_dialog;
|
||||
}
|
||||
|
||||
void LtsDialogHelper::retranslate()
|
||||
{
|
||||
if (m_dialog == nullptr)
|
||||
return;
|
||||
if (m_dialog == nullptr)
|
||||
return;
|
||||
|
||||
m_dialog->setContentsMargins(QMargins());
|
||||
if (m_dialog->layout())
|
||||
m_dialog->layout()->setContentsMargins(QMargins());
|
||||
m_dialog->setContentsMargins(QMargins());
|
||||
if (m_dialog->layout())
|
||||
m_dialog->layout()->setContentsMargins(QMargins());
|
||||
|
||||
bool oldChangesFlag = m_dialog->m_changesMade;
|
||||
bool oldChangesFlag = m_dialog->m_changesMade;
|
||||
|
||||
|
||||
m_dialog->retranslate();
|
||||
|
||||
m_dialog->retranslate();
|
||||
|
||||
if (oldChangesFlag)
|
||||
m_dialog->slotChangesMade();
|
||||
else
|
||||
m_dialog->resetChanges();
|
||||
if (oldChangesFlag)
|
||||
m_dialog->slotChangesMade();
|
||||
else
|
||||
m_dialog->resetChanges();
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogHelper::resizeEvent(QResizeEvent *e)
|
||||
void LtsDialogHelper::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
emit signalSizeChanged(e->size());
|
||||
emit signalSizeChanged(e->size());
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogHelper::changeEvent(QEvent *e)
|
||||
void LtsDialogHelper::changeEvent(QEvent* e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange)
|
||||
retranslate();
|
||||
QWidget::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange)
|
||||
retranslate();
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogHelper::onHScrollBarVisibilityChanged(bool visible)
|
||||
{
|
||||
if (m_dialog == nullptr || !m_dialog->layout())
|
||||
return;
|
||||
if (m_dialog == nullptr || !m_dialog->layout())
|
||||
return;
|
||||
|
||||
QMargins m = m_dialog->layout()->contentsMargins();
|
||||
m.setBottom(visible ? -1 : 0);
|
||||
m_dialog->layout()->setContentsMargins(m);
|
||||
QMargins m = m_dialog->layout()->contentsMargins();
|
||||
m.setBottom(visible ? -1 : 0);
|
||||
m_dialog->layout()->setContentsMargins(m);
|
||||
}
|
||||
|
||||
|
||||
void LtsDialogHelper::onVScrollBarVisibilityChanged(bool visible)
|
||||
{
|
||||
if (m_dialog == nullptr || !m_dialog->layout())
|
||||
return;
|
||||
if (m_dialog == nullptr || !m_dialog->layout())
|
||||
return;
|
||||
|
||||
QMargins m = m_dialog->layout()->contentsMargins();
|
||||
m.setRight(visible ? -1 : 0);
|
||||
m_dialog->layout()->setContentsMargins(m);
|
||||
QMargins m = m_dialog->layout()->contentsMargins();
|
||||
m.setRight(visible ? -1 : 0);
|
||||
m_dialog->layout()->setContentsMargins(m);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
|
||||
#include "lts_dialog_helper.moc"
|
||||
Executable → Regular
+24
-26
@@ -1,52 +1,50 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSize>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsDialogHelper;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsDialogButtonBox;
|
||||
class LtsDialog;
|
||||
|
||||
|
||||
|
||||
class LtsDialogHelper : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsDialogHelper(QWidget *parent = nullptr);
|
||||
~LtsDialogHelper();
|
||||
public:
|
||||
explicit LtsDialogHelper(QWidget* parent = nullptr);
|
||||
~LtsDialogHelper();
|
||||
|
||||
LtsDialogButtonBox *getButtonBox();
|
||||
void setDialog(LtsDialog *dialog);
|
||||
LtsDialog *getDialog();
|
||||
bool compare(const LtsDialog *dialog) const { return (dialog == m_dialog); }
|
||||
void retranslate();
|
||||
LtsDialogButtonBox* getButtonBox();
|
||||
void setDialog(LtsDialog* dialog);
|
||||
LtsDialog* getDialog();
|
||||
|
||||
signals:
|
||||
void signalSizeChanged(const QSize &size);
|
||||
bool compare(const LtsDialog* dialog) const
|
||||
{
|
||||
return (dialog == m_dialog);
|
||||
}
|
||||
|
||||
private:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
void onHScrollBarVisibilityChanged(bool visible);
|
||||
void onVScrollBarVisibilityChanged(bool visible);
|
||||
void retranslate();
|
||||
|
||||
Ui::LtsDialogHelper *m_ui;
|
||||
LtsDialog *m_dialog;
|
||||
signals:
|
||||
void signalSizeChanged(const QSize& size);
|
||||
|
||||
private:
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
void changeEvent(QEvent* e) override;
|
||||
void onHScrollBarVisibilityChanged(bool visible);
|
||||
void onVScrollBarVisibilityChanged(bool visible);
|
||||
|
||||
Ui::LtsDialogHelper* m_ui;
|
||||
LtsDialog* m_dialog;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+158
-174
@@ -1,247 +1,231 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "lts_drop_handler.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QButtonGroup;
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class QMenu;
|
||||
|
||||
namespace LtsWidgets {
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LtsToolButton;
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsDragIcon : public QWidget
|
||||
{
|
||||
public:
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QString context READ context WRITE setContext)
|
||||
Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(LtsWidgets::Designer::ButtonSize eButtonSize READ iconSizeDesigner WRITE setIconSizeDesigner)
|
||||
Q_PROPERTY(bool eForceFixedSize READ isForceFixedSize WRITE setForceFixedSize)
|
||||
Q_PROPERTY(bool isCheckable READ isCheckable WRITE setCheckable)
|
||||
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
|
||||
Q_PROPERTY(bool showDragIcon READ showDragIcon WRITE setShowDragIcon)
|
||||
Q_PROPERTY(bool isDraggable READ isDraggable WRITE setDraggable)
|
||||
public:
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QString context READ context WRITE setContext)
|
||||
Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(LtsWidgets::Designer::ButtonSize eButtonSize READ iconSizeDesigner WRITE setIconSizeDesigner)
|
||||
Q_PROPERTY(bool eForceFixedSize READ isForceFixedSize WRITE setForceFixedSize)
|
||||
Q_PROPERTY(bool isCheckable READ isCheckable WRITE setCheckable)
|
||||
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
|
||||
Q_PROPERTY(bool showDragIcon READ showDragIcon WRITE setShowDragIcon)
|
||||
Q_PROPERTY(bool isDraggable READ isDraggable WRITE setDraggable)
|
||||
|
||||
Q_PROPERTY(LtsWidgets::Designer::ButtonStyle eStyle READ buttonStyleDesigner WRITE setButtonStyleDesigner)
|
||||
|
||||
|
||||
Q_PROPERTY(LtsWidgets::Designer::ButtonStyle eStyle READ buttonStyleDesigner WRITE setButtonStyleDesigner)
|
||||
void setButtonStyleDesigner(Designer::ButtonStyle t)
|
||||
{
|
||||
setButtonStyle(static_cast<ButtonStyle>(t));
|
||||
}
|
||||
|
||||
Designer::ButtonStyle buttonStyleDesigner() const
|
||||
{
|
||||
return static_cast<Designer::ButtonStyle>(buttonStyle());
|
||||
}
|
||||
|
||||
|
||||
void setIconSizeDesigner(Designer::ButtonSize t)
|
||||
{
|
||||
setIconSize(static_cast<ButtonSize>(t));
|
||||
}
|
||||
|
||||
void setButtonStyleDesigner(Designer::ButtonStyle t) { setButtonStyle(static_cast<ButtonStyle>(t)); }
|
||||
Designer::ButtonSize iconSizeDesigner() const
|
||||
{
|
||||
return static_cast<Designer::ButtonSize>(iconSize());
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
explicit LtsDragIcon(QWidget* parent);
|
||||
|
||||
Designer::ButtonStyle buttonStyleDesigner() const { return static_cast<Designer::ButtonStyle>(buttonStyle()); }
|
||||
virtual ~LtsDragIcon() = default;
|
||||
|
||||
|
||||
void setMenu(QMenu* menu);
|
||||
|
||||
void setIconSizeDesigner(Designer::ButtonSize t) { setIconSize(static_cast<ButtonSize>(t)); }
|
||||
QMenu* menu() const;
|
||||
|
||||
|
||||
void setText(const QString& text);
|
||||
|
||||
Designer::ButtonSize iconSizeDesigner() const { return static_cast<Designer::ButtonSize>(iconSize()); }
|
||||
QString text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void setContext(const QString& context);
|
||||
|
||||
explicit LtsDragIcon(QWidget *parent);
|
||||
QString context() const
|
||||
{
|
||||
return m_context;
|
||||
}
|
||||
|
||||
virtual ~LtsDragIcon() = default;
|
||||
void setCheckable(bool checkable);
|
||||
|
||||
|
||||
bool isCheckable();
|
||||
|
||||
void setMenu(QMenu *menu);
|
||||
void setDraggable(bool draggable);
|
||||
|
||||
|
||||
bool isDraggable() const
|
||||
{
|
||||
return m_isDraggable;
|
||||
}
|
||||
|
||||
QMenu* menu() const;
|
||||
void setChecked(bool checked);
|
||||
|
||||
|
||||
bool isChecked() const;
|
||||
|
||||
void setText(const QString &text);
|
||||
void setShowDragIcon(bool showDragIcon)
|
||||
{
|
||||
m_showDragIcon = showDragIcon;
|
||||
}
|
||||
|
||||
|
||||
bool showDragIcon() const
|
||||
{
|
||||
return m_showDragIcon;
|
||||
}
|
||||
|
||||
QString text() const { return m_text; }
|
||||
void setSameWidgetDrop(bool drop);
|
||||
|
||||
|
||||
bool sameWidgetDrop() const;
|
||||
|
||||
void setContext(const QString &context);
|
||||
void setButtonStyle(ButtonStyle style);
|
||||
|
||||
|
||||
ButtonStyle buttonStyle() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
QString context() const { return m_context; }
|
||||
void setIconSize(ButtonSize buttonSize);
|
||||
|
||||
|
||||
ButtonSize iconSize() const
|
||||
{
|
||||
return m_buttonSize;
|
||||
}
|
||||
|
||||
void setCheckable(bool checkable);
|
||||
void setButtonVisible(bool visible);
|
||||
|
||||
|
||||
bool buttonVisible() const;
|
||||
|
||||
bool isCheckable();
|
||||
void setIcon(const QIcon& icon);
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
|
||||
void setForceFixedSize(bool force);
|
||||
|
||||
void setDraggable(bool draggable);
|
||||
bool isForceFixedSize() const
|
||||
{
|
||||
return m_forceFixedSize;
|
||||
}
|
||||
|
||||
|
||||
void setAction(QAction* action);
|
||||
|
||||
bool isDraggable() const { return m_isDraggable; }
|
||||
void addToButtonGroup(QButtonGroup* btnGrp, int btnGrpId);
|
||||
|
||||
|
||||
void setDropHandlerKey(qulonglong key)
|
||||
{
|
||||
m_dropHandlerKey = key;
|
||||
}
|
||||
|
||||
void setChecked(bool checked);
|
||||
void addMimeData(const QString& mimeType, const QByteArray& data);
|
||||
bool removeMimeData(const QString& mimeType);
|
||||
void removeAllMimeData();
|
||||
|
||||
|
||||
void setAcceptDrops(bool on);
|
||||
|
||||
bool isChecked() const;
|
||||
qulonglong dropHandlerKey() const
|
||||
{
|
||||
return m_dropHandlerKey;
|
||||
}
|
||||
|
||||
|
||||
void setIdentifier(const QString& id)
|
||||
{
|
||||
m_identifier = id;
|
||||
}
|
||||
|
||||
void setShowDragIcon(bool showDragIcon) { m_showDragIcon = showDragIcon; }
|
||||
bool showDragIcon() const { return m_showDragIcon; }
|
||||
QString identifier() const
|
||||
{
|
||||
return m_identifier;
|
||||
}
|
||||
|
||||
|
||||
void setModification(const QString& id)
|
||||
{
|
||||
m_modification = id;
|
||||
setIcon(m_icon);
|
||||
}
|
||||
|
||||
void setSameWidgetDrop(bool drop);
|
||||
QString modification() const
|
||||
{
|
||||
return m_modification;
|
||||
}
|
||||
|
||||
|
||||
void removeModification()
|
||||
{
|
||||
m_modification = QString();
|
||||
setIcon(m_icon);
|
||||
}
|
||||
|
||||
bool sameWidgetDrop() const;
|
||||
signals:
|
||||
|
||||
|
||||
void clicked();
|
||||
|
||||
void setButtonStyle(ButtonStyle style);
|
||||
void toggled(bool);
|
||||
void newDropEvent(QDropEvent* e);
|
||||
void dropSuc();
|
||||
|
||||
|
||||
void enabledChanged(bool);
|
||||
|
||||
ButtonStyle buttonStyle() const { return m_style; }
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent* e) override;
|
||||
void dropEvent(QDropEvent* e) override;
|
||||
void initButton();
|
||||
|
||||
|
||||
private:
|
||||
void setStyleToButton();
|
||||
QIcon modifyIcon(const QIcon& icon);
|
||||
void generateToolTip();
|
||||
|
||||
void setIconSize(ButtonSize buttonSize);
|
||||
|
||||
|
||||
|
||||
ButtonSize iconSize() const { return m_buttonSize; }
|
||||
|
||||
|
||||
|
||||
void setButtonVisible(bool visible);
|
||||
|
||||
|
||||
|
||||
bool buttonVisible() const;
|
||||
|
||||
|
||||
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
|
||||
|
||||
QIcon icon() const { return m_icon; }
|
||||
|
||||
|
||||
|
||||
void setForceFixedSize(bool force);
|
||||
|
||||
|
||||
|
||||
bool isForceFixedSize() const { return m_forceFixedSize; }
|
||||
|
||||
|
||||
|
||||
void setAction(QAction *action);
|
||||
|
||||
|
||||
|
||||
void addToButtonGroup(QButtonGroup *btnGrp, int btnGrpId);
|
||||
|
||||
|
||||
|
||||
void setDropHandlerKey(qulonglong key) { m_dropHandlerKey = key; }
|
||||
|
||||
|
||||
|
||||
void addMimeData(const QString &mimeType, const QByteArray &data);
|
||||
bool removeMimeData(const QString &mimeType);
|
||||
void removeAllMimeData();
|
||||
|
||||
|
||||
|
||||
void setAcceptDrops(bool on);
|
||||
|
||||
qulonglong dropHandlerKey() const { return m_dropHandlerKey; }
|
||||
|
||||
|
||||
void setIdentifier(const QString &id) { m_identifier = id; }
|
||||
QString identifier() const { return m_identifier; }
|
||||
|
||||
void setModification(const QString &id) { m_modification = id; setIcon(m_icon); }
|
||||
QString modification() const { return m_modification; }
|
||||
void removeModification() { m_modification = QString(); setIcon(m_icon);}
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
void clicked();
|
||||
|
||||
|
||||
|
||||
void toggled(bool);
|
||||
void newDropEvent(QDropEvent *e);
|
||||
void dropSuc();
|
||||
|
||||
void enabledChanged(bool);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void dropEvent(QDropEvent *e) override;
|
||||
void initButton();
|
||||
|
||||
private:
|
||||
void setStyleToButton();
|
||||
QIcon modifyIcon(const QIcon &icon);
|
||||
void generateToolTip();
|
||||
|
||||
protected slots:
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
QHBoxLayout *m_lay;
|
||||
LtsToolButton *m_toolButton;
|
||||
QIcon m_icon;
|
||||
QLabel *m_dragLabel;
|
||||
QString m_text;
|
||||
QString m_identifier;
|
||||
QString m_modification;
|
||||
ButtonStyle m_style;
|
||||
bool m_forceFixedSize;
|
||||
bool m_isDraggable;
|
||||
qulonglong m_dropHandlerKey;
|
||||
ButtonSize m_buttonSize;
|
||||
bool m_showDragIcon;
|
||||
QString m_context;
|
||||
protected slots:
|
||||
void changeEvent(QEvent* event) override;
|
||||
|
||||
private:
|
||||
QHBoxLayout* m_lay;
|
||||
LtsToolButton* m_toolButton;
|
||||
QIcon m_icon;
|
||||
QLabel* m_dragLabel;
|
||||
QString m_text;
|
||||
QString m_identifier;
|
||||
QString m_modification;
|
||||
ButtonStyle m_style;
|
||||
bool m_forceFixedSize;
|
||||
bool m_isDraggable;
|
||||
qulonglong m_dropHandlerKey;
|
||||
ButtonSize m_buttonSize;
|
||||
bool m_showDragIcon;
|
||||
QString m_context;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+10
-19
@@ -1,31 +1,22 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
class QMimeData;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
class LtsDropHandler
|
||||
{
|
||||
public:
|
||||
class LtsDropHandler
|
||||
{
|
||||
public:
|
||||
LtsDropHandler() = default;
|
||||
virtual ~LtsDropHandler() = default;
|
||||
|
||||
LtsDropHandler() = default;
|
||||
virtual ~LtsDropHandler() = default;
|
||||
LtsDropHandler(const LtsDropHandler&) = delete;
|
||||
LtsDropHandler& operator=(const LtsDropHandler&) = delete;
|
||||
|
||||
LtsDropHandler( const LtsDropHandler & ) = delete;
|
||||
LtsDropHandler & operator = ( const LtsDropHandler & ) = delete;
|
||||
virtual void doDrop(int x, int y, const QMimeData* mimeData) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
virtual void doDrop( int x, int y, const QMimeData * mimeData ) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+28
-33
@@ -1,60 +1,55 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_elided_label.h"
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QResizeEvent>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
void LtsElidedLabel::setElideMode(Qt::TextElideMode elideMode)
|
||||
{
|
||||
m_elideMode = elideMode;
|
||||
m_cachedText.clear();
|
||||
update();
|
||||
m_elideMode = elideMode;
|
||||
m_cachedText.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void LtsElidedLabel::resizeEvent(QResizeEvent *e)
|
||||
void LtsElidedLabel::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
QLabel::resizeEvent(e);
|
||||
m_cachedText.clear();
|
||||
QLabel::resizeEvent(e);
|
||||
m_cachedText.clear();
|
||||
}
|
||||
|
||||
void LtsElidedLabel::paintEvent(QPaintEvent *e)
|
||||
void LtsElidedLabel::paintEvent(QPaintEvent* e)
|
||||
{
|
||||
if (m_elideMode == Qt::ElideNone)
|
||||
return QLabel::paintEvent(e);
|
||||
if (m_elideMode == Qt::ElideNone)
|
||||
return QLabel::paintEvent(e);
|
||||
|
||||
updateCachedTexts();
|
||||
QLabel::setText(m_cachedElidedText);
|
||||
QLabel::paintEvent(e);
|
||||
QLabel::setText(m_cachedText);
|
||||
updateCachedTexts();
|
||||
QLabel::setText(m_cachedElidedText);
|
||||
QLabel::paintEvent(e);
|
||||
QLabel::setText(m_cachedText);
|
||||
}
|
||||
|
||||
void LtsElidedLabel::updateCachedTexts()
|
||||
{
|
||||
|
||||
const auto txt = text();
|
||||
if (m_cachedText == txt)
|
||||
return;
|
||||
m_cachedText = txt;
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
m_cachedElidedText = fm.elidedText(text(),
|
||||
m_elideMode,
|
||||
width(),
|
||||
Qt::TextShowMnemonic);
|
||||
if (!m_cachedText.isEmpty())
|
||||
{
|
||||
const QString showFirstCharacter = m_cachedText.at(0) + QStringLiteral("...");
|
||||
|
||||
const auto txt = text();
|
||||
if (m_cachedText == txt)
|
||||
return;
|
||||
m_cachedText = txt;
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
m_cachedElidedText = fm.elidedText(text(), m_elideMode, width(), Qt::TextShowMnemonic);
|
||||
if (!m_cachedText.isEmpty())
|
||||
{
|
||||
const QString showFirstCharacter = m_cachedText.at(0) + QStringLiteral("...");
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||
const int width = fm.width(showFirstCharacter);
|
||||
const int width = fm.width(showFirstCharacter);
|
||||
#else
|
||||
const int width = fm.horizontalAdvance(showFirstCharacter);
|
||||
const int width = fm.horizontalAdvance(showFirstCharacter);
|
||||
#endif
|
||||
setMinimumWidth(width + 1);
|
||||
}
|
||||
setMinimumWidth(width + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+22
-19
@@ -1,37 +1,40 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include "ltswidgets_export.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsElidedLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(Qt::TextElideMode ElideMode READ elideMode WRITE setElideMode)
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(Qt::TextElideMode ElideMode READ elideMode WRITE setElideMode)
|
||||
|
||||
using QLabel::QLabel;
|
||||
using QLabel::QLabel;
|
||||
|
||||
void setElideMode(Qt::TextElideMode elideMode);
|
||||
Qt::TextElideMode elideMode() const { return m_elideMode; }
|
||||
void setElideMode(Qt::TextElideMode elideMode);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
Qt::TextElideMode elideMode() const
|
||||
{
|
||||
return m_elideMode;
|
||||
}
|
||||
|
||||
private:
|
||||
void updateCachedTexts();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
|
||||
private:
|
||||
Qt::TextElideMode m_elideMode = Qt::ElideRight;
|
||||
QString m_cachedElidedText;
|
||||
QString m_cachedText;
|
||||
private:
|
||||
void updateCachedTexts();
|
||||
|
||||
private:
|
||||
Qt::TextElideMode m_elideMode = Qt::ElideRight;
|
||||
QString m_cachedElidedText;
|
||||
QString m_cachedText;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+25
-28
@@ -1,58 +1,55 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_events.h"
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
QEvent::Type LtsLinkEvent::eventTypeId()
|
||||
{
|
||||
static QEvent::Type sLinkEventId = QEvent::None;
|
||||
if (sLinkEventId == QEvent::None)
|
||||
sLinkEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sLinkEventId;
|
||||
static QEvent::Type sLinkEventId = QEvent::None;
|
||||
if (sLinkEventId == QEvent::None)
|
||||
sLinkEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sLinkEventId;
|
||||
}
|
||||
|
||||
QEvent::Type SaveImageEvent::saveImageEventId()
|
||||
{
|
||||
static QEvent::Type sSaveImageEventId = QEvent::None;
|
||||
if (sSaveImageEventId == QEvent::None)
|
||||
sSaveImageEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sSaveImageEventId;
|
||||
static QEvent::Type sSaveImageEventId = QEvent::None;
|
||||
if (sSaveImageEventId == QEvent::None)
|
||||
sSaveImageEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sSaveImageEventId;
|
||||
}
|
||||
|
||||
QEvent::Type SetMarkerEvent::setMarkerEventId()
|
||||
{
|
||||
static QEvent::Type sSetMarkerEventId = QEvent::None;
|
||||
if (sSetMarkerEventId == QEvent::None)
|
||||
sSetMarkerEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sSetMarkerEventId;
|
||||
static QEvent::Type sSetMarkerEventId = QEvent::None;
|
||||
if (sSetMarkerEventId == QEvent::None)
|
||||
sSetMarkerEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sSetMarkerEventId;
|
||||
}
|
||||
|
||||
QEvent::Type AddMarkerEvent::addMarkerEventId()
|
||||
{
|
||||
static QEvent::Type sAddMarkerEventId = QEvent::None;
|
||||
if (sAddMarkerEventId == QEvent::None)
|
||||
sAddMarkerEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sAddMarkerEventId;
|
||||
static QEvent::Type sAddMarkerEventId = QEvent::None;
|
||||
if (sAddMarkerEventId == QEvent::None)
|
||||
sAddMarkerEventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return sAddMarkerEventId;
|
||||
}
|
||||
|
||||
QEvent::Type AddSnapshotEvent::addSnapshotEventId()
|
||||
{
|
||||
static QEvent::Type eventId = QEvent::None;
|
||||
if (eventId == QEvent::None)
|
||||
eventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return eventId;
|
||||
static QEvent::Type eventId = QEvent::None;
|
||||
if (eventId == QEvent::None)
|
||||
eventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return eventId;
|
||||
}
|
||||
|
||||
QEvent::Type SaveSnapshotEvent::saveSnapshotEventId()
|
||||
{
|
||||
static QEvent::Type eventId = QEvent::None;
|
||||
if (eventId == QEvent::None)
|
||||
eventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return eventId;
|
||||
static QEvent::Type eventId = QEvent::None;
|
||||
if (eventId == QEvent::None)
|
||||
eventId = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+82
-56
@@ -1,95 +1,121 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QEvent>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
#include <QUrl>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsLinkEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
explicit LtsLinkEvent(QUrl url, QWidget *sourceBaseLayoutWidget)
|
||||
: QEvent(eventTypeId())
|
||||
, m_url(std::move(url))
|
||||
, m_sourceBaseLayoutWidget(sourceBaseLayoutWidget)
|
||||
{}
|
||||
public:
|
||||
explicit LtsLinkEvent(QUrl url, QWidget* sourceBaseLayoutWidget)
|
||||
: QEvent(eventTypeId()), m_url(std::move(url)), m_sourceBaseLayoutWidget(sourceBaseLayoutWidget)
|
||||
{
|
||||
}
|
||||
|
||||
static QEvent::Type eventTypeId();
|
||||
QWidget *sourceBaseLayoutWidget() const { return m_sourceBaseLayoutWidget.data(); }
|
||||
QUrl url() const { return m_url; }
|
||||
private:
|
||||
QUrl m_url;
|
||||
QPointer<QWidget> m_sourceBaseLayoutWidget;
|
||||
static QEvent::Type eventTypeId();
|
||||
|
||||
QWidget* sourceBaseLayoutWidget() const
|
||||
{
|
||||
return m_sourceBaseLayoutWidget.data();
|
||||
}
|
||||
|
||||
QUrl url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
||||
|
||||
private:
|
||||
QUrl m_url;
|
||||
QPointer<QWidget> m_sourceBaseLayoutWidget;
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT SaveImageEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
SaveImageEvent(QWidget *w, QPixmap &&pm)
|
||||
: QEvent(saveImageEventId()), m_widget(w), m_pix(std::move(pm))
|
||||
{}
|
||||
public:
|
||||
SaveImageEvent(QWidget* w, QPixmap&& pm) : QEvent(saveImageEventId()), m_widget(w), m_pix(std::move(pm)) {}
|
||||
|
||||
const QPixmap &pixmap() const { return m_pix; }
|
||||
QWidget *widget() const { return m_widget.data(); }
|
||||
static QEvent::Type saveImageEventId();
|
||||
private:
|
||||
QPointer<QWidget> m_widget;
|
||||
QPixmap m_pix;
|
||||
const QPixmap& pixmap() const
|
||||
{
|
||||
return m_pix;
|
||||
}
|
||||
|
||||
QWidget* widget() const
|
||||
{
|
||||
return m_widget.data();
|
||||
}
|
||||
|
||||
static QEvent::Type saveImageEventId();
|
||||
|
||||
private:
|
||||
QPointer<QWidget> m_widget;
|
||||
QPixmap m_pix;
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT AddMarkerEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
AddMarkerEvent()
|
||||
: QEvent(addMarkerEventId())
|
||||
{}
|
||||
static QEvent::Type addMarkerEventId();
|
||||
public:
|
||||
AddMarkerEvent() : QEvent(addMarkerEventId()) {}
|
||||
|
||||
static QEvent::Type addMarkerEventId();
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT SetMarkerEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
SetMarkerEvent(const QString &description)
|
||||
: QEvent(setMarkerEventId()), m_description(description)
|
||||
{}
|
||||
const QString &getDescription() const { return m_description; }
|
||||
void setDescription(const QString &description) { m_description = description; }
|
||||
static QEvent::Type setMarkerEventId();
|
||||
private:
|
||||
QString m_description;
|
||||
public:
|
||||
SetMarkerEvent(const QString& description) : QEvent(setMarkerEventId()), m_description(description) {}
|
||||
|
||||
const QString& getDescription() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void setDescription(const QString& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
static QEvent::Type setMarkerEventId();
|
||||
|
||||
private:
|
||||
QString m_description;
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT AddSnapshotEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
AddSnapshotEvent()
|
||||
: QEvent(addSnapshotEventId())
|
||||
{}
|
||||
static QEvent::Type addSnapshotEventId();
|
||||
public:
|
||||
AddSnapshotEvent() : QEvent(addSnapshotEventId()) {}
|
||||
|
||||
static QEvent::Type addSnapshotEventId();
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT SaveSnapshotEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
SaveSnapshotEvent(const QString &description)
|
||||
: QEvent(saveSnapshotEventId()), m_description(description)
|
||||
{}
|
||||
const QString &getDescription() const { return m_description; }
|
||||
void setDescription(const QString &description) { m_description = description; }
|
||||
static QEvent::Type saveSnapshotEventId();
|
||||
private:
|
||||
QString m_description;
|
||||
public:
|
||||
SaveSnapshotEvent(const QString& description) : QEvent(saveSnapshotEventId()), m_description(description) {}
|
||||
|
||||
const QString& getDescription() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void setDescription(const QString& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
static QEvent::Type saveSnapshotEventId();
|
||||
|
||||
private:
|
||||
QString m_description;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+18
-28
@@ -1,47 +1,37 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
enum class Behaviour
|
||||
{
|
||||
Popup = 0,
|
||||
Modal,
|
||||
enum class Behaviour {
|
||||
Popup = 0,
|
||||
Modal,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsFramelessDialog : public QDialog
|
||||
class LTSWIDGETS_EXPORT LtsFramelessDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
explicit LtsFramelessDialog(QWidget* parent = nullptr, const Behaviour& behaviour = Behaviour::Popup);
|
||||
virtual ~LtsFramelessDialog();
|
||||
|
||||
explicit LtsFramelessDialog(QWidget *parent = nullptr, const Behaviour &behaviour = Behaviour::Popup);
|
||||
virtual ~LtsFramelessDialog();
|
||||
public Q_SLOTS:
|
||||
void onUpdateGeometry();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onUpdateGeometry();
|
||||
private:
|
||||
QRect screenRectFromPoint(const QPoint &pos) const;
|
||||
void addTouchScroll(QWidget *widget);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
private:
|
||||
QRect screenRectFromPoint(const QPoint& pos) const;
|
||||
void addTouchScroll(QWidget* widget);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+111
-141
@@ -1,225 +1,195 @@
|
||||
|
||||
|
||||
#include "lts_global_wait_dialog.h"
|
||||
#include "lts_progress_dialog_helper.h"
|
||||
#include "lts_overlay_loading.h"
|
||||
|
||||
#include "lts_dialog.h"
|
||||
#include "lts_frameless_dialog.h"
|
||||
#include "lts_overlay_loading.h"
|
||||
#include "lts_progress_dialog_helper.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <execinfo.h>
|
||||
#include <dlfcn.h>
|
||||
#include <cxxabi.h>
|
||||
#include <cxxabi.h>
|
||||
#include <dlfcn.h>
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsGlobalWaitDialog::~LtsGlobalWaitDialog()
|
||||
{
|
||||
delete m_progressDialog;
|
||||
delete m_progressDialog;
|
||||
}
|
||||
|
||||
|
||||
LtsGlobalWaitDialog::LtsGlobalWaitDialog()
|
||||
: m_waitingCount(0)
|
||||
, m_visible(true)
|
||||
, m_progressDialog(new LtsProgressDialogHelper(nullptr))
|
||||
, m_hideTimer(new QTimer(this))
|
||||
: m_waitingCount(0), m_visible(true), m_progressDialog(new LtsProgressDialogHelper(nullptr)),
|
||||
m_hideTimer(new QTimer(this))
|
||||
{
|
||||
m_hideTimer->setSingleShot(true);
|
||||
m_hideTimer->setInterval(500);
|
||||
connect(m_hideTimer, &QTimer::timeout,
|
||||
this, &LtsGlobalWaitDialog::hideIt);
|
||||
m_hideTimer->setSingleShot(true);
|
||||
m_hideTimer->setInterval(500);
|
||||
connect(m_hideTimer, &QTimer::timeout, this, &LtsGlobalWaitDialog::hideIt);
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::unarm()
|
||||
{
|
||||
m_armed = false;
|
||||
hideIt();
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::rearm()
|
||||
{
|
||||
m_armed = true;
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::setVisible(bool visible)
|
||||
{
|
||||
if (m_waitingCount > 0 && visible)
|
||||
showIt();
|
||||
|
||||
if (m_waitingCount < 1 && !visible)
|
||||
m_armed = false;
|
||||
hideIt();
|
||||
}
|
||||
|
||||
void LtsGlobalWaitDialog::rearm()
|
||||
{
|
||||
m_armed = true;
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void LtsGlobalWaitDialog::setVisible(bool visible)
|
||||
{
|
||||
if (m_waitingCount > 0 && visible)
|
||||
showIt();
|
||||
|
||||
if (m_waitingCount < 1 && !visible)
|
||||
hideIt();
|
||||
}
|
||||
|
||||
void LtsGlobalWaitDialog::showIt()
|
||||
{
|
||||
if (m_progressDialog->isShown())
|
||||
return;
|
||||
if (m_progressDialog->isShown())
|
||||
return;
|
||||
|
||||
m_hideTimer->stop();
|
||||
if (m_armed)
|
||||
{
|
||||
m_progressDialog->slotShowWaitForReplyWindow();
|
||||
}
|
||||
m_hideTimer->stop();
|
||||
if (m_armed)
|
||||
{
|
||||
m_progressDialog->slotShowWaitForReplyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::hideIt()
|
||||
{
|
||||
if (!m_progressDialog->isShown())
|
||||
return;
|
||||
if (!m_progressDialog->isShown())
|
||||
return;
|
||||
|
||||
m_hideTimer->stop();
|
||||
m_progressDialog->slotStopWaitForReplyWindow();
|
||||
m_hideTimer->stop();
|
||||
m_progressDialog->slotStopWaitForReplyWindow();
|
||||
}
|
||||
|
||||
|
||||
void bt()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
void *callstack[128];
|
||||
const int nMaxFrames = sizeof(callstack) / sizeof(callstack[0]);
|
||||
int nFrames = backtrace(callstack, nMaxFrames);
|
||||
char **symbols = backtrace_symbols(callstack, nFrames);
|
||||
void* callstack[128];
|
||||
const int nMaxFrames = sizeof(callstack) / sizeof(callstack[0]);
|
||||
int nFrames = backtrace(callstack, nMaxFrames);
|
||||
char** symbols = backtrace_symbols(callstack, nFrames);
|
||||
|
||||
for (int i = 1; i < nFrames; i++)
|
||||
{
|
||||
QString address(QStringLiteral("0x%1").arg(QString::number(*(quintptr *)callstack[i], 16)));
|
||||
QString function;
|
||||
int offset = -1;
|
||||
|
||||
Dl_info info;
|
||||
if (dladdr(callstack[i], &info) && info.dli_sname)
|
||||
for (int i = 1; i < nFrames; i++)
|
||||
{
|
||||
char *demangled = nullptr;
|
||||
int status = -1;
|
||||
if (info.dli_sname[0] == '_')
|
||||
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
|
||||
QString address(QStringLiteral("0x%1").arg(QString::number(*(quintptr*)callstack[i], 16)));
|
||||
QString function;
|
||||
int offset = -1;
|
||||
|
||||
function = QString::fromUtf8(status == 0 ? demangled : info.dli_sname == 0 ? symbols[i] : info.dli_sname);
|
||||
offset = (char *)callstack[i] - (char *)info.dli_saddr;
|
||||
Dl_info info;
|
||||
if (dladdr(callstack[i], &info) && info.dli_sname)
|
||||
{
|
||||
char* demangled = nullptr;
|
||||
int status = -1;
|
||||
if (info.dli_sname[0] == '_')
|
||||
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
|
||||
|
||||
free(demangled);
|
||||
}
|
||||
else
|
||||
{
|
||||
function = QString::fromUtf8(symbols[i]);
|
||||
function = QString::fromUtf8(status == 0 ? demangled : info.dli_sname == 0 ? symbols[i] : info.dli_sname);
|
||||
offset = (char*)callstack[i] - (char*)info.dli_saddr;
|
||||
|
||||
free(demangled);
|
||||
}
|
||||
else
|
||||
{
|
||||
function = QString::fromUtf8(symbols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
|
||||
|
||||
free(symbols);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::wait(QWidget *parent, const QString &customText)
|
||||
void LtsGlobalWaitDialog::wait(QWidget* parent, const QString& customText)
|
||||
{
|
||||
m_progressDialog->setParentWidget(parent);
|
||||
if (m_waitingCount < 1 && m_visible)
|
||||
showIt();
|
||||
m_progressDialog->setParentWidget(parent);
|
||||
if (m_waitingCount < 1 && m_visible)
|
||||
showIt();
|
||||
|
||||
setCustomText(customText);
|
||||
setCustomText(customText);
|
||||
|
||||
m_waitingCount++;
|
||||
|
||||
|
||||
|
||||
|
||||
m_waitingCount++;
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::setCustomText(const QString &customText)
|
||||
void LtsGlobalWaitDialog::setCustomText(const QString& customText)
|
||||
{
|
||||
m_progressDialog->setCustomText(customText);
|
||||
m_progressDialog->setCustomText(customText);
|
||||
}
|
||||
|
||||
|
||||
void LtsGlobalWaitDialog::done()
|
||||
{
|
||||
if (m_waitingCount == 0)
|
||||
{
|
||||
|
||||
m_hideTimer->start();
|
||||
return;
|
||||
}
|
||||
if (m_waitingCount == 0)
|
||||
{
|
||||
|
||||
Q_ASSERT(m_waitingCount > 0);
|
||||
m_hideTimer->start();
|
||||
return;
|
||||
}
|
||||
|
||||
m_waitingCount--;
|
||||
|
||||
Q_ASSERT(m_waitingCount > 0);
|
||||
|
||||
if (m_waitingCount == 0)
|
||||
m_hideTimer->start();
|
||||
m_waitingCount--;
|
||||
|
||||
if (m_waitingCount == 0)
|
||||
m_hideTimer->start();
|
||||
}
|
||||
|
||||
static LtsGlobalWaitDialog *s_gwdInstance = nullptr;
|
||||
static LtsGlobalWaitDialog* s_gwdInstance = nullptr;
|
||||
|
||||
void LtsGlobalWaitDialog::cleanupGwdInstance()
|
||||
{
|
||||
delete s_gwdInstance;
|
||||
s_gwdInstance = nullptr;
|
||||
delete s_gwdInstance;
|
||||
s_gwdInstance = nullptr;
|
||||
}
|
||||
|
||||
LtsGlobalWaitDialog *LtsGlobalWaitDialog::getInstance()
|
||||
LtsGlobalWaitDialog* LtsGlobalWaitDialog::getInstance()
|
||||
{
|
||||
if (!s_gwdInstance)
|
||||
{
|
||||
s_gwdInstance = new LtsGlobalWaitDialog;
|
||||
qAddPostRoutine(&LtsGlobalWaitDialog::cleanupGwdInstance);
|
||||
}
|
||||
return s_gwdInstance;
|
||||
if (!s_gwdInstance)
|
||||
{
|
||||
s_gwdInstance = new LtsGlobalWaitDialog;
|
||||
qAddPostRoutine(&LtsGlobalWaitDialog::cleanupGwdInstance);
|
||||
}
|
||||
return s_gwdInstance;
|
||||
}
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
|
||||
|
||||
|
||||
Waiter::Waiter(const QString &customText)
|
||||
Waiter::Waiter(const QString& customText)
|
||||
{
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->wait(nullptr, customText);
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->wait(nullptr, customText);
|
||||
}
|
||||
|
||||
|
||||
Waiter::Waiter(LtsWidgets::LtsDialog *parent, const QString &customText)
|
||||
: m_parent(parent)
|
||||
Waiter::Waiter(LtsWidgets::LtsDialog* parent, const QString& customText) : m_parent(parent)
|
||||
{
|
||||
m_oldClosableState = m_parent->isClosable();
|
||||
m_parent->setClosable(false);
|
||||
m_parent->setCurrentlyBlocking(true);
|
||||
auto *wait = new LtsWidgets::LtsOverlayLoading;
|
||||
wait->setText(customText.isEmpty() ? QObject::tr("Waiting for server reply...") : customText);
|
||||
m_parent->setOverlay(wait);
|
||||
m_loadingOverlay = wait;
|
||||
m_oldClosableState = m_parent->isClosable();
|
||||
m_parent->setClosable(false);
|
||||
m_parent->setCurrentlyBlocking(true);
|
||||
auto* wait = new LtsWidgets::LtsOverlayLoading;
|
||||
wait->setText(customText.isEmpty() ? QObject::tr("Waiting for server reply...") : customText);
|
||||
m_parent->setOverlay(wait);
|
||||
m_loadingOverlay = wait;
|
||||
}
|
||||
|
||||
|
||||
Waiter::~Waiter()
|
||||
{
|
||||
if (m_loadingOverlay == nullptr)
|
||||
{
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
||||
return;
|
||||
}
|
||||
if (m_loadingOverlay == nullptr)
|
||||
{
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
||||
return;
|
||||
}
|
||||
|
||||
m_parent->setClosable(m_oldClosableState);
|
||||
m_parent->setCurrentlyBlocking(false);
|
||||
m_loadingOverlay->deleteLater();
|
||||
m_parent->setClosable(m_oldClosableState);
|
||||
m_parent->setCurrentlyBlocking(false);
|
||||
m_loadingOverlay->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+36
-38
@@ -1,69 +1,67 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QTimer;
|
||||
class QWidget;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsDialog;
|
||||
class LtsOverlayLoading;
|
||||
class LtsProgressDialogHelper;
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsGlobalWaitDialog : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static LtsGlobalWaitDialog* getInstance();
|
||||
void wait(QWidget *parent, const QString &customText = QString());
|
||||
void wait(const QString &customText = QString()) { wait(nullptr, customText); }
|
||||
void done();
|
||||
void setVisible(bool visible = true);
|
||||
void setCustomText(const QString &customText = QString());
|
||||
void unarm();
|
||||
void rearm();
|
||||
public:
|
||||
static LtsGlobalWaitDialog* getInstance();
|
||||
void wait(QWidget* parent, const QString& customText = QString());
|
||||
|
||||
private:
|
||||
friend struct LtsGlobalWaitDialogHandler;
|
||||
void wait(const QString& customText = QString())
|
||||
{
|
||||
wait(nullptr, customText);
|
||||
}
|
||||
|
||||
LtsGlobalWaitDialog();
|
||||
~LtsGlobalWaitDialog();
|
||||
static void cleanupGwdInstance();
|
||||
void done();
|
||||
void setVisible(bool visible = true);
|
||||
void setCustomText(const QString& customText = QString());
|
||||
void unarm();
|
||||
void rearm();
|
||||
|
||||
void showIt();
|
||||
void hideIt();
|
||||
private:
|
||||
friend struct LtsGlobalWaitDialogHandler;
|
||||
|
||||
int m_waitingCount;
|
||||
bool m_visible;
|
||||
bool m_armed { true };
|
||||
LtsProgressDialogHelper *m_progressDialog;
|
||||
QTimer *m_hideTimer;
|
||||
LtsGlobalWaitDialog();
|
||||
~LtsGlobalWaitDialog();
|
||||
static void cleanupGwdInstance();
|
||||
|
||||
void showIt();
|
||||
void hideIt();
|
||||
|
||||
int m_waitingCount;
|
||||
bool m_visible;
|
||||
bool m_armed{true};
|
||||
LtsProgressDialogHelper* m_progressDialog;
|
||||
QTimer* m_hideTimer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace LtsWidgets
|
||||
|
||||
class LTSWIDGETS_EXPORT Waiter
|
||||
{
|
||||
public:
|
||||
explicit Waiter(const QString &customText = {});
|
||||
explicit Waiter(LtsWidgets::LtsDialog *parent, const QString &customText = {});
|
||||
~Waiter();
|
||||
public:
|
||||
explicit Waiter(const QString& customText = {});
|
||||
explicit Waiter(LtsWidgets::LtsDialog* parent, const QString& customText = {});
|
||||
~Waiter();
|
||||
|
||||
private:
|
||||
LtsWidgets::LtsOverlayLoading *m_loadingOverlay { nullptr };
|
||||
LtsWidgets::LtsDialog *m_parent { nullptr };
|
||||
bool m_oldClosableState { false };
|
||||
private:
|
||||
LtsWidgets::LtsOverlayLoading* m_loadingOverlay{nullptr};
|
||||
LtsWidgets::LtsDialog* m_parent{nullptr};
|
||||
bool m_oldClosableState{false};
|
||||
};
|
||||
Executable → Regular
+27
-41
@@ -1,62 +1,48 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <QGridLayout>
|
||||
#include <QVector>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
class QWidget;
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsGridLayout : public QGridLayout
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsGridLayout(LtsWidgets::ButtonSize buttonSize, QWidget* parent = nullptr, int maxColumn = 1);
|
||||
|
||||
explicit LtsGridLayout(LtsWidgets::ButtonSize buttonSize, QWidget *parent = nullptr, int maxColumn = 1);
|
||||
void add_widget(QWidget* widget);
|
||||
|
||||
|
||||
void setAutoSize(bool enable);
|
||||
|
||||
void add_widget(QWidget *widget);
|
||||
void setMaxColumn(int max);
|
||||
|
||||
|
||||
private:
|
||||
void addWidgetInternal(QWidget* widget);
|
||||
|
||||
void setAutoSize(bool enable);
|
||||
|
||||
|
||||
|
||||
void setMaxColumn(int max);
|
||||
|
||||
|
||||
private:
|
||||
void addWidgetInternal(QWidget *widget);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onParentResize(QResizeEvent *e);
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
void onWidgetDestroyed();
|
||||
private:
|
||||
|
||||
LtsWidgets::ButtonSize m_buttonSize;
|
||||
int m_defaultMaxColumn;
|
||||
int m_maxColumn;
|
||||
int m_colSize;
|
||||
QVector<QWidget *> m_widgetList;
|
||||
QRect m_oldGeo;
|
||||
QSize m_oldSize;
|
||||
bool m_autoSize;
|
||||
public Q_SLOTS:
|
||||
void onParentResize(QResizeEvent* e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onWidgetDestroyed();
|
||||
|
||||
private:
|
||||
LtsWidgets::ButtonSize m_buttonSize;
|
||||
int m_defaultMaxColumn;
|
||||
int m_maxColumn;
|
||||
int m_colSize;
|
||||
QVector<QWidget*> m_widgetList;
|
||||
QRect m_oldGeo;
|
||||
QSize m_oldSize;
|
||||
bool m_autoSize;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+31
-46
@@ -1,70 +1,55 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QPointF>
|
||||
#include <QtCore/QPair>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QtCore/QPair>
|
||||
#include <QtCore/QPointF>
|
||||
#include <QtCore/QVector>
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsHeightPlotWidget final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsHeightPlotWidget(QWidget *parent = nullptr);
|
||||
virtual ~LtsHeightPlotWidget();
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsHeightPlotWidget(QWidget* parent = nullptr);
|
||||
virtual ~LtsHeightPlotWidget();
|
||||
|
||||
void clearView();
|
||||
void clearView();
|
||||
|
||||
|
||||
void setData(const QVector<QPair<QPointF, double>>& data);
|
||||
|
||||
void setData(const QVector<QPair<QPointF, double> > &data);
|
||||
|
||||
void setMarks(const QVector<QPointF>& data);
|
||||
|
||||
void setMarks(const QVector<QPointF> &data);
|
||||
void setBackgroundBrush(const QBrush& brush);
|
||||
|
||||
|
||||
void setTextFont(const QFont& f);
|
||||
|
||||
void setBackgroundBrush(const QBrush &brush);
|
||||
|
||||
void setAxisPen(const QPen& pen);
|
||||
|
||||
void setTextFont(const QFont &f);
|
||||
|
||||
void setPositionPen(const QPen& pen);
|
||||
|
||||
void setAxisPen(const QPen &pen);
|
||||
|
||||
void setViewLinePen(const QPen& pen);
|
||||
|
||||
void setPositionPen(const QPen &pen);
|
||||
|
||||
void setContourBrush(const QBrush& brush);
|
||||
|
||||
void setViewLinePen(const QPen &pen);
|
||||
|
||||
void setMarkerPen(const QPen& pen);
|
||||
|
||||
void setContourBrush(const QBrush &brush);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void setMarkerPen(const QPen &pen);
|
||||
void mousePositionChanged(const QPointF& curPoint, double curHeight, double mouseHeight);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void startLineOfSight(const QPointF& startPoint);
|
||||
|
||||
void mousePositionChanged(const QPointF &curPoint, double curHeight, double mouseHeight);
|
||||
|
||||
void stopLineOfSight();
|
||||
|
||||
void startLineOfSight(const QPointF &startPoint);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
void mouseMoveEvent(QMouseEvent* e) override;
|
||||
void mouseReleaseEvent(QMouseEvent* e) override;
|
||||
|
||||
void stopLineOfSight();
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
class Private;
|
||||
Private *const d;
|
||||
class Private;
|
||||
Private* const d;
|
||||
};
|
||||
Executable → Regular
+36
-43
@@ -1,28 +1,27 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_info_dialog.h"
|
||||
|
||||
#include "ui_lts_info_dialog.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QFile>
|
||||
#include <QPixmap>
|
||||
|
||||
#ifndef LTS_VERSION_MAJOR
|
||||
#define LTS_VERSION_MAJOR "undefined"
|
||||
#define LTS_VERSION_MAJOR "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_MINOR
|
||||
#define LTS_VERSION_MINOR "undefined"
|
||||
#define LTS_VERSION_MINOR "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_PATCH
|
||||
#define LTS_VERSION_PATCH "undefined"
|
||||
#define LTS_VERSION_PATCH "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_DATE
|
||||
#define LTS_VERSION_DATE "undefined"
|
||||
#define LTS_VERSION_DATE "undefined"
|
||||
#endif
|
||||
#ifndef JENKINS_BUILD_NUMBER
|
||||
#define JENKINS_BUILD_NUMBER "unknown"
|
||||
#define JENKINS_BUILD_NUMBER "unknown"
|
||||
#endif
|
||||
static const char ver_major[] = LTS_VERSION_MAJOR;
|
||||
static const char ver_minor[] = LTS_VERSION_MINOR;
|
||||
@@ -33,49 +32,43 @@ static const char ver_jenkins[] = JENKINS_BUILD_NUMBER;
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsInfoDialog::LtsInfoDialog(QWidget *parent)
|
||||
: LtsFramelessDialog(parent)
|
||||
, m_ui(new Ui::LtsInfoDialog)
|
||||
LtsInfoDialog::LtsInfoDialog(QWidget* parent) : LtsFramelessDialog(parent), m_ui(new Ui::LtsInfoDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->setupUi(this);
|
||||
|
||||
QFont f = font();
|
||||
f.setBold(true);
|
||||
m_ui->lblVersion->setFont(f);
|
||||
m_ui->lblDate->setFont(f);
|
||||
QFont f = font();
|
||||
f.setBold(true);
|
||||
m_ui->lblVersion->setFont(f);
|
||||
m_ui->lblDate->setFont(f);
|
||||
|
||||
const QString versionString = QStringLiteral("%1.%2-%3 (rev: %4)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch));
|
||||
m_ui->lblVersion->setText(versionString);
|
||||
m_ui->lblDate->setText(QString::fromLatin1(ver_date));
|
||||
const QString versionString = QStringLiteral("%1.%2-%3 (rev: %4)")
|
||||
.arg(QString::fromLatin1(ver_major), QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins), QString::fromLatin1(ver_patch));
|
||||
m_ui->lblVersion->setText(versionString);
|
||||
m_ui->lblDate->setText(QString::fromLatin1(ver_date));
|
||||
|
||||
|
||||
QString projectLogoFilename(QStringLiteral(":project/login_logo.png"));
|
||||
if (!QFile(projectLogoFilename).exists())
|
||||
projectLogoFilename = QStringLiteral(":/project/logo.png");
|
||||
QString projectLogoFilename(QStringLiteral(":project/login_logo.png"));
|
||||
if (!QFile(projectLogoFilename).exists())
|
||||
projectLogoFilename = QStringLiteral(":/project/logo.png");
|
||||
|
||||
QPixmap pixmap(projectLogoFilename);
|
||||
QPixmap pixmap(projectLogoFilename);
|
||||
|
||||
if (pixmap.isNull())
|
||||
{
|
||||
qWarning() << "LtsInfoDialog: project logo missing or is not an valid image " << projectLogoFilename;
|
||||
}
|
||||
else
|
||||
{
|
||||
int max = m_ui->lblProjectLogo->maximumHeight();
|
||||
pixmap = pixmap.scaled(999, max * 0.85f, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
m_ui->lblProjectLogo->setPixmap(pixmap);
|
||||
}
|
||||
connect(m_ui->pbClose, &QPushButton::clicked, this, &LtsInfoDialog::close);
|
||||
if (pixmap.isNull())
|
||||
{
|
||||
qWarning() << "LtsInfoDialog: project logo missing or is not an valid image " << projectLogoFilename;
|
||||
}
|
||||
else
|
||||
{
|
||||
int max = m_ui->lblProjectLogo->maximumHeight();
|
||||
pixmap = pixmap.scaled(999, max * 0.85f, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
m_ui->lblProjectLogo->setPixmap(pixmap);
|
||||
}
|
||||
connect(m_ui->pbClose, &QPushButton::clicked, this, &LtsInfoDialog::close);
|
||||
}
|
||||
|
||||
|
||||
LtsInfoDialog::~LtsInfoDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+8
-10
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_frameless_dialog.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@@ -17,13 +15,13 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsInfoDialog : public LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsInfoDialog(QWidget *parent = nullptr);
|
||||
~LtsInfoDialog();
|
||||
public:
|
||||
explicit LtsInfoDialog(QWidget* parent = nullptr);
|
||||
~LtsInfoDialog();
|
||||
|
||||
private:
|
||||
Ui::LtsInfoDialog *m_ui;
|
||||
private:
|
||||
Ui::LtsInfoDialog* m_ui;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+91
-102
@@ -1,148 +1,137 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_led_widget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
void LtsLedWidget::resizeEvent(QResizeEvent *event)
|
||||
void LtsLedWidget::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
switch (m_aspectHint) {
|
||||
case AspectHint::NoHint:
|
||||
{
|
||||
|
||||
switch (m_aspectHint)
|
||||
{
|
||||
case AspectHint::NoHint: {
|
||||
|
||||
|
||||
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
break;
|
||||
}
|
||||
case AspectHint::HeightIsWidth:
|
||||
setMinimumHeight(event->size().width());
|
||||
setMaximumHeight(event->size().width());
|
||||
setMinimumWidth(0);
|
||||
setMaximumWidth(65000);
|
||||
break;
|
||||
case AspectHint::WidthIsHeight:
|
||||
setMinimumHeight(0);
|
||||
setMaximumHeight(65000);
|
||||
setMinimumWidth(event->size().height());
|
||||
setMaximumWidth(event->size().height());
|
||||
break;
|
||||
}
|
||||
QWidget::resizeEvent(event);
|
||||
break;
|
||||
}
|
||||
case AspectHint::HeightIsWidth:
|
||||
setMinimumHeight(event->size().width());
|
||||
setMaximumHeight(event->size().width());
|
||||
setMinimumWidth(0);
|
||||
setMaximumWidth(65000);
|
||||
break;
|
||||
case AspectHint::WidthIsHeight:
|
||||
setMinimumHeight(0);
|
||||
setMaximumHeight(65000);
|
||||
setMinimumWidth(event->size().height());
|
||||
setMaximumWidth(event->size().height());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr double GRADIENT_KEY_LOWER = 0.3;
|
||||
static constexpr double GRADIENT_KEY_UPPER = 0.9;
|
||||
static constexpr int GRADIENT_VALUE_LOWER = 125;
|
||||
static constexpr int GRADIENT_VALUE_UPPER = 165;
|
||||
static constexpr double GRADIENT_CENTER_OFFSET = 5.0;
|
||||
static constexpr double GRADIENT_FOCALPOINT_OFFSET = 2.7;
|
||||
static constexpr double PERCENTAGE_OF_BORDER = 0.1;
|
||||
static constexpr int DARK_FACTOR = 200;
|
||||
|
||||
|
||||
static constexpr double GRADIENT_KEY_LOWER = 0.3;
|
||||
static constexpr double GRADIENT_KEY_UPPER = 0.9;
|
||||
static constexpr int GRADIENT_VALUE_LOWER = 125;
|
||||
static constexpr int GRADIENT_VALUE_UPPER = 165;
|
||||
static constexpr double GRADIENT_CENTER_OFFSET = 5.0;
|
||||
static constexpr double GRADIENT_FOCALPOINT_OFFSET = 2.7;
|
||||
static constexpr double PERCENTAGE_OF_BORDER = 0.1;
|
||||
static constexpr int DARK_FACTOR = 200;
|
||||
|
||||
LtsLedWidget::LtsLedWidget(QWidget *parent, const QColor &oncolor, const QColor &offcolor, bool useGradient, int animtime)
|
||||
: QWidget(parent)
|
||||
, m_status(true)
|
||||
, m_oncolor(oncolor)
|
||||
, m_offcolor(offcolor)
|
||||
, m_currentcolor(oncolor)
|
||||
, m_gradient(useGradient)
|
||||
, m_animTime(animtime)
|
||||
LtsLedWidget::LtsLedWidget(QWidget* parent, const QColor& oncolor, const QColor& offcolor, bool useGradient,
|
||||
int animtime)
|
||||
: QWidget(parent), m_status(true), m_oncolor(oncolor), m_offcolor(offcolor), m_currentcolor(oncolor),
|
||||
m_gradient(useGradient), m_animTime(animtime)
|
||||
{
|
||||
setObjectName(QString::fromUtf8("LtsLedWidget"));
|
||||
setObjectName(QString::fromUtf8("LtsLedWidget"));
|
||||
}
|
||||
|
||||
void LtsLedWidget::paintEvent(QPaintEvent *pe)
|
||||
void LtsLedWidget::paintEvent(QPaintEvent* pe)
|
||||
{
|
||||
Q_UNUSED(pe);
|
||||
QPainter p;
|
||||
p.begin(this);
|
||||
p.setOpacity(QWidget::isEnabled() ? 1.00 : 0.5);
|
||||
Q_UNUSED(pe);
|
||||
QPainter p;
|
||||
p.begin(this);
|
||||
p.setOpacity(QWidget::isEnabled() ? 1.00 : 0.5);
|
||||
|
||||
int minSize = height() > width() ? width() : height();
|
||||
if (m_gradient)
|
||||
{
|
||||
QRadialGradient grad(QPointF(width(), height()) / GRADIENT_CENTER_OFFSET,
|
||||
minSize,
|
||||
QPointF(width(), height()) / GRADIENT_FOCALPOINT_OFFSET);
|
||||
grad.setColorAt(GRADIENT_KEY_LOWER, m_currentcolor.lighter(GRADIENT_VALUE_LOWER));
|
||||
grad.setColorAt(GRADIENT_KEY_UPPER, m_currentcolor.darker(GRADIENT_VALUE_UPPER));
|
||||
p.setBrush(grad);
|
||||
}
|
||||
else
|
||||
p.setBrush(QBrush(m_currentcolor, Qt::SolidPattern));
|
||||
int minSize = height() > width() ? width() : height();
|
||||
if (m_gradient)
|
||||
{
|
||||
QRadialGradient grad(QPointF(width(), height()) / GRADIENT_CENTER_OFFSET, minSize,
|
||||
QPointF(width(), height()) / GRADIENT_FOCALPOINT_OFFSET);
|
||||
grad.setColorAt(GRADIENT_KEY_LOWER, m_currentcolor.lighter(GRADIENT_VALUE_LOWER));
|
||||
grad.setColorAt(GRADIENT_KEY_UPPER, m_currentcolor.darker(GRADIENT_VALUE_UPPER));
|
||||
p.setBrush(grad);
|
||||
}
|
||||
else
|
||||
p.setBrush(QBrush(m_currentcolor, Qt::SolidPattern));
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setPen(QPen(Qt::black, PERCENTAGE_OF_BORDER * minSize, Qt::SolidLine, Qt::SquareCap));
|
||||
p.drawEllipse(QPointF(width(), height()) / 2.0,
|
||||
width() / (2.0 * (1.00 + PERCENTAGE_OF_BORDER)),
|
||||
height() / (2.0 * (1.00 + PERCENTAGE_OF_BORDER)));
|
||||
p.end();
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setPen(QPen(Qt::black, PERCENTAGE_OF_BORDER * minSize, Qt::SolidLine, Qt::SquareCap));
|
||||
p.drawEllipse(QPointF(width(), height()) / 2.0, width() / (2.0 * (1.00 + PERCENTAGE_OF_BORDER)),
|
||||
height() / (2.0 * (1.00 + PERCENTAGE_OF_BORDER)));
|
||||
p.end();
|
||||
}
|
||||
|
||||
void LtsLedWidget::animate()
|
||||
{
|
||||
QPropertyAnimation *anim = new QPropertyAnimation(this, "currentcolor");
|
||||
anim->setDuration(m_animTime);
|
||||
anim->setEasingCurve(QEasingCurve::OutBack);
|
||||
anim->setStartValue(m_currentcolor);
|
||||
anim->setEndValue(m_status ? m_oncolor : m_offcolor == Qt::black ? m_oncolor.darker(DARK_FACTOR) : m_offcolor);
|
||||
anim->start(QPropertyAnimation::DeleteWhenStopped);
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(this, "currentcolor");
|
||||
anim->setDuration(m_animTime);
|
||||
anim->setEasingCurve(QEasingCurve::OutBack);
|
||||
anim->setStartValue(m_currentcolor);
|
||||
anim->setEndValue(m_status ? m_oncolor : m_offcolor == Qt::black ? m_oncolor.darker(DARK_FACTOR) : m_offcolor);
|
||||
anim->start(QPropertyAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void LtsLedWidget::setStatus(bool status)
|
||||
{
|
||||
if (m_status == status)
|
||||
return;
|
||||
m_status = status;
|
||||
animate();
|
||||
if (m_status == status)
|
||||
return;
|
||||
m_status = status;
|
||||
animate();
|
||||
}
|
||||
|
||||
void LtsLedWidget::setUseGradient(bool useGradient)
|
||||
{
|
||||
if (m_gradient == useGradient)
|
||||
return;
|
||||
m_gradient = useGradient;
|
||||
repaint();
|
||||
if (m_gradient == useGradient)
|
||||
return;
|
||||
m_gradient = useGradient;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void LtsLedWidget::setColor(const QColor &oncolor, const QColor &offcolor)
|
||||
void LtsLedWidget::setColor(const QColor& oncolor, const QColor& offcolor)
|
||||
{
|
||||
setOnColor(oncolor);
|
||||
setOffColor(offcolor);
|
||||
setOnColor(oncolor);
|
||||
setOffColor(offcolor);
|
||||
}
|
||||
|
||||
void LtsLedWidget::setOnColor(const QColor &oncolor)
|
||||
void LtsLedWidget::setOnColor(const QColor& oncolor)
|
||||
{
|
||||
if (m_oncolor == oncolor)
|
||||
return;
|
||||
m_oncolor = oncolor;
|
||||
if (m_status)
|
||||
animate();
|
||||
if (m_oncolor == oncolor)
|
||||
return;
|
||||
m_oncolor = oncolor;
|
||||
if (m_status)
|
||||
animate();
|
||||
}
|
||||
|
||||
void LtsLedWidget::setOffColor(const QColor &offcolor)
|
||||
void LtsLedWidget::setOffColor(const QColor& offcolor)
|
||||
{
|
||||
if (m_offcolor == offcolor)
|
||||
return;
|
||||
m_offcolor = offcolor;
|
||||
if (!m_status)
|
||||
animate();
|
||||
if (m_offcolor == offcolor)
|
||||
return;
|
||||
m_offcolor = offcolor;
|
||||
if (!m_status)
|
||||
animate();
|
||||
}
|
||||
|
||||
void LtsLedWidget::setCurrentColor(const QColor ¤tcolor)
|
||||
void LtsLedWidget::setCurrentColor(const QColor& currentcolor)
|
||||
{
|
||||
if (m_currentcolor == currentcolor)
|
||||
return;
|
||||
m_currentcolor = currentcolor;
|
||||
repaint();
|
||||
if (m_currentcolor == currentcolor)
|
||||
return;
|
||||
m_currentcolor = currentcolor;
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+71
-82
@@ -1,118 +1,107 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsLedWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class AspectHint
|
||||
{
|
||||
WidthIsHeight,
|
||||
NoHint,
|
||||
HeightIsWidth
|
||||
};
|
||||
Q_ENUM(AspectHint)
|
||||
public:
|
||||
enum class AspectHint { WidthIsHeight, NoHint, HeightIsWidth };
|
||||
Q_ENUM(AspectHint)
|
||||
|
||||
Q_PROPERTY(QColor oncolor READ onColor WRITE setOnColor)
|
||||
Q_PROPERTY(QColor offcolor READ offColor WRITE setOffColor)
|
||||
Q_PROPERTY(bool status READ status WRITE setStatus)
|
||||
Q_PROPERTY(bool usesGradient READ usesGradient WRITE setUseGradient)
|
||||
Q_PROPERTY(int animTime READ animTime WRITE setAnimTime)
|
||||
Q_PROPERTY(AspectHint aspectHint READ aspectHint WRITE setAspectHint)
|
||||
Q_PROPERTY(QColor currentcolor READ currentColor WRITE setCurrentColor DESIGNABLE false)
|
||||
Q_PROPERTY(QColor oncolor READ onColor WRITE setOnColor)
|
||||
Q_PROPERTY(QColor offcolor READ offColor WRITE setOffColor)
|
||||
Q_PROPERTY(bool status READ status WRITE setStatus)
|
||||
Q_PROPERTY(bool usesGradient READ usesGradient WRITE setUseGradient)
|
||||
Q_PROPERTY(int animTime READ animTime WRITE setAnimTime)
|
||||
Q_PROPERTY(AspectHint aspectHint READ aspectHint WRITE setAspectHint)
|
||||
Q_PROPERTY(QColor currentcolor READ currentColor WRITE setCurrentColor DESIGNABLE false)
|
||||
|
||||
|
||||
explicit LtsLedWidget(QWidget* parent = nullptr, const QColor& oncolor = Qt::red,
|
||||
const QColor& offcolor = Qt::black, bool useGradient = true, int animtime = 0);
|
||||
|
||||
explicit LtsLedWidget(QWidget *parent = nullptr, const QColor &oncolor = Qt::red, const QColor &offcolor = Qt::black, bool useGradient = true, int animtime = 0);
|
||||
void paintEvent(QPaintEvent* pe);
|
||||
|
||||
void paintEvent(QPaintEvent *pe);
|
||||
void setAnimTime(int time)
|
||||
{
|
||||
m_animTime = time;
|
||||
}
|
||||
|
||||
|
||||
int animTime() const
|
||||
{
|
||||
return m_animTime;
|
||||
}
|
||||
|
||||
void setAnimTime(int time) { m_animTime = time; }
|
||||
bool status() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
|
||||
void setUseGradient(bool useGradient);
|
||||
|
||||
int animTime() const { return m_animTime; }
|
||||
bool usesGradient() const
|
||||
{
|
||||
return m_gradient;
|
||||
}
|
||||
|
||||
|
||||
void setOnColor(const QColor& oncolor);
|
||||
|
||||
bool status() const { return m_status; }
|
||||
QColor onColor() const
|
||||
{
|
||||
return m_oncolor;
|
||||
}
|
||||
|
||||
|
||||
void setOffColor(const QColor& offcolor);
|
||||
|
||||
void setUseGradient(bool useGradient);
|
||||
QColor offColor() const
|
||||
{
|
||||
return m_offcolor;
|
||||
}
|
||||
|
||||
|
||||
void setColor(const QColor& oncolor, const QColor& offcolor = Qt::black);
|
||||
|
||||
bool usesGradient() const { return m_gradient; }
|
||||
QColor currentColor() const
|
||||
{
|
||||
return m_currentcolor;
|
||||
}
|
||||
|
||||
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
void setOnColor(const QColor &oncolor);
|
||||
AspectHint aspectHint() const
|
||||
{
|
||||
return m_aspectHint;
|
||||
}
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
QColor onColor() const { return m_oncolor; }
|
||||
void setStatus(bool status);
|
||||
|
||||
|
||||
void setAspectHint(AspectHint aspectHint)
|
||||
{
|
||||
m_aspectHint = aspectHint;
|
||||
}
|
||||
|
||||
void setOffColor(const QColor &offcolor);
|
||||
private:
|
||||
void setCurrentColor(const QColor& currentcolor);
|
||||
|
||||
|
||||
void animate();
|
||||
|
||||
QColor offColor() const { return m_offcolor; }
|
||||
bool m_status;
|
||||
QColor m_oncolor;
|
||||
QColor m_offcolor;
|
||||
QColor m_currentcolor;
|
||||
|
||||
|
||||
|
||||
void setColor(const QColor &oncolor, const QColor &offcolor = Qt::black);
|
||||
|
||||
|
||||
|
||||
QColor currentColor() const { return m_currentcolor; }
|
||||
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
AspectHint aspectHint() const { return m_aspectHint; }
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
void setStatus(bool status);
|
||||
|
||||
void setAspectHint(AspectHint aspectHint)
|
||||
{
|
||||
m_aspectHint = aspectHint;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void setCurrentColor(const QColor ¤tcolor);
|
||||
|
||||
|
||||
|
||||
void animate();
|
||||
|
||||
bool m_status;
|
||||
QColor m_oncolor;
|
||||
QColor m_offcolor;
|
||||
QColor m_currentcolor;
|
||||
|
||||
bool m_gradient;
|
||||
int m_animTime;
|
||||
AspectHint m_aspectHint = AspectHint::NoHint;
|
||||
bool m_gradient;
|
||||
int m_animTime;
|
||||
AspectHint m_aspectHint = AspectHint::NoHint;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+36
-54
@@ -1,87 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
#include "lts_frameless_dialog.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QHash>
|
||||
|
||||
|
||||
class QWidget;
|
||||
class QHBoxLayout;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
enum class Button {
|
||||
UNKNOWN = 0,
|
||||
Ok = 1,
|
||||
Yes = 2,
|
||||
No = 4,
|
||||
Cancel = 8,
|
||||
|
||||
|
||||
enum class Button
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
Ok = 1,
|
||||
Yes = 2,
|
||||
No = 4,
|
||||
Cancel = 8,
|
||||
|
||||
Apply = 16,
|
||||
Discard = 32,
|
||||
Apply = 16,
|
||||
Discard = 32,
|
||||
};
|
||||
Q_DECLARE_FLAGS(Buttons, Button)
|
||||
|
||||
inline uint qHash(LtsWidgets::Button b)
|
||||
{
|
||||
return ::qHash(static_cast<int>(b));
|
||||
return ::qHash(static_cast<int>(b));
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace LtsMessageDialog
|
||||
namespace LtsMessageDialog
|
||||
{
|
||||
|
||||
|
||||
LTSWIDGETS_EXPORT Button showMessage(QWidget* parent,
|
||||
const QString &message,
|
||||
const QString &title = QString(),
|
||||
const Behaviour behaviour = Behaviour::Modal,
|
||||
const Buttons buttons = Button::Ok,
|
||||
const QHash<Button, QString> &buttonTexts = QHash<Button, QString>());
|
||||
LTSWIDGETS_EXPORT Button askApplyDiscardCancel(QWidget *parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LTSWIDGETS_EXPORT Button showMessage(QWidget* parent, const QString& message, const QString& title = QString(),
|
||||
const Behaviour behaviour = Behaviour::Modal, const Buttons buttons = Button::Ok,
|
||||
const QHash<Button, QString>& buttonTexts = QHash<Button, QString>());
|
||||
LTSWIDGETS_EXPORT Button askApplyDiscardCancel(QWidget* parent);
|
||||
} // namespace LtsMessageDialog
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsMessageDialogNew : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsMessageDialogNew(QWidget* parent,
|
||||
const QString &message,
|
||||
const QString &title = QString(),
|
||||
const Behaviour behaviour = Behaviour::Modal,
|
||||
const Buttons buttons = Button::Ok,
|
||||
const QHash<Button, QString> &buttonTexts = QHash<Button, QString>(),
|
||||
bool deleteOnClose = true );
|
||||
public:
|
||||
explicit LtsMessageDialogNew(QWidget* parent, const QString& message, const QString& title = QString(),
|
||||
const Behaviour behaviour = Behaviour::Modal, const Buttons buttons = Button::Ok,
|
||||
const QHash<Button, QString>& buttonTexts = QHash<Button, QString>(),
|
||||
bool deleteOnClose = true);
|
||||
|
||||
private:
|
||||
LtsFramelessDialog *m_dialog;
|
||||
private:
|
||||
LtsFramelessDialog* m_dialog;
|
||||
|
||||
QPushButton *addButton(const QString &text, QHBoxLayout *thatLayout, LtsFramelessDialog *dialog, const Button &button, QWidget *parent);
|
||||
|
||||
|
||||
signals:
|
||||
void ok();
|
||||
void yes();
|
||||
void no();
|
||||
void apply();
|
||||
void discard();
|
||||
void cancel();
|
||||
QPushButton* addButton(const QString& text, QHBoxLayout* thatLayout, LtsFramelessDialog* dialog,
|
||||
const Button& button, QWidget* parent);
|
||||
|
||||
signals:
|
||||
void ok();
|
||||
void yes();
|
||||
void no();
|
||||
void apply();
|
||||
void discard();
|
||||
void cancel();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(LtsWidgets::Buttons)
|
||||
Executable → Regular
+21
-28
@@ -7,46 +7,39 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
|
||||
class QPushButton;
|
||||
class QHBoxLayout;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LtsMessageDialogHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsMessageDialogHelper(QObject *parent = nullptr);
|
||||
~LtsMessageDialogHelper() = default;
|
||||
public:
|
||||
explicit LtsMessageDialogHelper(QObject* parent = nullptr);
|
||||
~LtsMessageDialogHelper() = default;
|
||||
|
||||
Button showMessage(QWidget *parent,
|
||||
const QString &message,
|
||||
const QString &title,
|
||||
Behaviour behaviour,
|
||||
LtsWidgets::Buttons buttons,
|
||||
const QHash<Button, QString> &buttonTexts);
|
||||
Button showMessage(QWidget* parent, const QString& message, const QString& title, Behaviour behaviour,
|
||||
LtsWidgets::Buttons buttons, const QHash<Button, QString>& buttonTexts);
|
||||
|
||||
private:
|
||||
QPushButton *addButton(const QString &text, QHBoxLayout *thatLayout, LtsFramelessDialog *dialog, const Button &button, QWidget *parent);
|
||||
private:
|
||||
QPushButton* addButton(const QString& text, QHBoxLayout* thatLayout, LtsFramelessDialog* dialog,
|
||||
const Button& button, QWidget* parent);
|
||||
|
||||
Button m_result;
|
||||
LtsFramelessDialog *m_dialog;
|
||||
Button m_result;
|
||||
LtsFramelessDialog* m_dialog;
|
||||
|
||||
private slots:
|
||||
void slotOkay();
|
||||
void slotYes();
|
||||
void slotNo();
|
||||
void slotCancel();
|
||||
void slotApply();
|
||||
void slotDiscard();
|
||||
private slots:
|
||||
void slotOkay();
|
||||
void slotYes();
|
||||
void slotNo();
|
||||
void slotCancel();
|
||||
void slotApply();
|
||||
void slotDiscard();
|
||||
|
||||
signals:
|
||||
void signalQuitEventLoop();
|
||||
signals:
|
||||
void signalQuitEventLoop();
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+65
-66
@@ -1,114 +1,113 @@
|
||||
#include "lts_msec_date_time_edit.h"
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(QWidget *parent)
|
||||
: QDateTimeEdit(parent)
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(QWidget* parent) : QDateTimeEdit(parent)
|
||||
{
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
}
|
||||
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QDateTime &dt, QWidget *parent)
|
||||
: QDateTimeEdit(dt, parent)
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QDateTime& dt, QWidget* parent) : QDateTimeEdit(dt, parent)
|
||||
{
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
}
|
||||
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QDate &d, QWidget *parent)
|
||||
: QDateTimeEdit(d, parent)
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QDate& d, QWidget* parent) : QDateTimeEdit(d, parent)
|
||||
{
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
}
|
||||
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QTime &t, QWidget *parent)
|
||||
: QDateTimeEdit(t, parent)
|
||||
LtsMSecDateTimeEdit::LtsMSecDateTimeEdit(const QTime& t, QWidget* parent) : QDateTimeEdit(t, parent)
|
||||
{
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
setWrapping(true);
|
||||
setDisplayFormat(QLatin1String("dd.MM.yy HH:mm:ss.zzz"));
|
||||
connect(this, &LtsMSecDateTimeEdit::editingFinished, this, &LtsMSecDateTimeEdit::onEditingFinished);
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::stepBy(int steps)
|
||||
{
|
||||
switch (currentSection()) {
|
||||
case QDateTimeEdit::MonthSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addMonths(steps));
|
||||
break;
|
||||
case QDateTimeEdit::YearSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addYears(steps));
|
||||
break;
|
||||
case QDateTimeEdit::DaySection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addDays(steps));
|
||||
break;
|
||||
case QDateTimeEdit::HourSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps * 3600));
|
||||
break;
|
||||
case QDateTimeEdit::MinuteSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps * 60));
|
||||
break;
|
||||
case QDateTimeEdit::SecondSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps));
|
||||
break;
|
||||
case QDateTimeEdit::MSecSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addMSecs(steps * m_msecStepSize));
|
||||
break;
|
||||
case QDateTimeEdit::NoSection:
|
||||
case QDateTimeEdit::AmPmSection:
|
||||
case QDateTimeEdit::TimeSections_Mask:
|
||||
case QDateTimeEdit::DateSections_Mask:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (currentSection())
|
||||
{
|
||||
case QDateTimeEdit::MonthSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addMonths(steps));
|
||||
break;
|
||||
case QDateTimeEdit::YearSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addYears(steps));
|
||||
break;
|
||||
case QDateTimeEdit::DaySection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addDays(steps));
|
||||
break;
|
||||
case QDateTimeEdit::HourSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps * 3600));
|
||||
break;
|
||||
case QDateTimeEdit::MinuteSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps * 60));
|
||||
break;
|
||||
case QDateTimeEdit::SecondSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addSecs(steps));
|
||||
break;
|
||||
case QDateTimeEdit::MSecSection:
|
||||
QDateTimeEdit::setDateTime(dateTime().addMSecs(steps * m_msecStepSize));
|
||||
break;
|
||||
case QDateTimeEdit::NoSection:
|
||||
case QDateTimeEdit::AmPmSection:
|
||||
case QDateTimeEdit::TimeSections_Mask:
|
||||
case QDateTimeEdit::DateSections_Mask:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qint64 LtsMSecDateTimeEdit::msecsSinceEpoch() const
|
||||
{
|
||||
return dateTime().toMSecsSinceEpoch() - (m_timezoneHoursOffset * 3600 * 1000);
|
||||
return dateTime().toMSecsSinceEpoch() - (m_timezoneHoursOffset * 3600 * 1000);
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::setTimezoneHoursOffset(int timezoneHoursOffset)
|
||||
{
|
||||
qint64 b4 = msecsSinceEpoch();
|
||||
m_timezoneHoursOffset = timezoneHoursOffset;
|
||||
setMsecsSinceEpoch(b4);
|
||||
qint64 b4 = msecsSinceEpoch();
|
||||
m_timezoneHoursOffset = timezoneHoursOffset;
|
||||
setMsecsSinceEpoch(b4);
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::setDateTime(const QDateTime &dateTime)
|
||||
void LtsMSecDateTimeEdit::setDateTime(const QDateTime& dateTime)
|
||||
{
|
||||
|
||||
setMsecsSinceEpoch(QDateTime::fromMSecsSinceEpoch(dateTime.toMSecsSinceEpoch(), Qt::TimeSpec::OffsetFromUTC, m_timezoneHoursOffset * 3600).toMSecsSinceEpoch());
|
||||
|
||||
setMsecsSinceEpoch(QDateTime::fromMSecsSinceEpoch(dateTime.toMSecsSinceEpoch(), Qt::TimeSpec::OffsetFromUTC,
|
||||
m_timezoneHoursOffset * 3600)
|
||||
.toMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::setMsecsSinceEpoch(qint64 msecs)
|
||||
{
|
||||
QDateTimeEdit::setDateTime(QDateTime::fromMSecsSinceEpoch(msecs, Qt::TimeSpec::OffsetFromUTC, m_timezoneHoursOffset * 3600));
|
||||
QDateTimeEdit::setDateTime(
|
||||
QDateTime::fromMSecsSinceEpoch(msecs, Qt::TimeSpec::OffsetFromUTC, m_timezoneHoursOffset * 3600));
|
||||
}
|
||||
|
||||
int LtsMSecDateTimeEdit::msecStepSize() const
|
||||
{
|
||||
return m_msecStepSize;
|
||||
return m_msecStepSize;
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::setMsecStepSize(int msecStepSize)
|
||||
{
|
||||
m_msecStepSize = msecStepSize;
|
||||
m_msecStepSize = msecStepSize;
|
||||
}
|
||||
|
||||
void LtsMSecDateTimeEdit::onEditingFinished()
|
||||
{
|
||||
qint64 val = msecsSinceEpoch();
|
||||
if (val % m_msecStepSize == 0)
|
||||
return;
|
||||
val = (val + (m_msecStepSize/2) ) / m_msecStepSize * m_msecStepSize;
|
||||
setMsecsSinceEpoch(val);
|
||||
qint64 val = msecsSinceEpoch();
|
||||
if (val % m_msecStepSize == 0)
|
||||
return;
|
||||
val = (val + (m_msecStepSize / 2)) / m_msecStepSize * m_msecStepSize;
|
||||
setMsecsSinceEpoch(val);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+31
-27
@@ -1,42 +1,46 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QDateTimeEdit>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QDateTimeEdit>
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets {
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsMSecDateTimeEdit : public QDateTimeEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int msecStepSize READ msecStepSize WRITE setMsecStepSize)
|
||||
Q_PROPERTY(int msecStepSize READ msecStepSize WRITE setMsecStepSize)
|
||||
|
||||
public:
|
||||
explicit LtsMSecDateTimeEdit(QWidget *parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QDateTime &dt, QWidget *parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QDate &d, QWidget *parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QTime &t, QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit LtsMSecDateTimeEdit(QWidget* parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QDateTime& dt, QWidget* parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QDate& d, QWidget* parent = nullptr);
|
||||
explicit LtsMSecDateTimeEdit(const QTime& t, QWidget* parent = nullptr);
|
||||
|
||||
qint64 msecsSinceEpoch() const;
|
||||
int timezoneHoursOffset() const { return m_timezoneHoursOffset; }
|
||||
void stepBy(int steps) override;
|
||||
int msecStepSize() const;
|
||||
qint64 msecsSinceEpoch() const;
|
||||
|
||||
public slots:
|
||||
void setDateTime(const QDateTime &dateTime);
|
||||
void setMsecsSinceEpoch(qint64 msecs);
|
||||
void setMsecStepSize(int msecStepSize);
|
||||
void setTimezoneHoursOffset(int timezoneHoursOffset);
|
||||
int timezoneHoursOffset() const
|
||||
{
|
||||
return m_timezoneHoursOffset;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void onEditingFinished();
|
||||
void stepBy(int steps) override;
|
||||
int msecStepSize() const;
|
||||
|
||||
private:
|
||||
int m_msecStepSize = 10;
|
||||
int m_timezoneHoursOffset = 0;
|
||||
public slots:
|
||||
void setDateTime(const QDateTime& dateTime);
|
||||
void setMsecsSinceEpoch(qint64 msecs);
|
||||
void setMsecStepSize(int msecStepSize);
|
||||
void setTimezoneHoursOffset(int timezoneHoursOffset);
|
||||
|
||||
private slots:
|
||||
void onEditingFinished();
|
||||
|
||||
private:
|
||||
int m_msecStepSize = 10;
|
||||
int m_timezoneHoursOffset = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+171
-224
@@ -1,314 +1,261 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_multi_range_spinbox.h"
|
||||
#include <utility>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsMultiRangeSpinBox::LtsMultiRangeSpinBox(QWidget *parent)
|
||||
: QSpinBox(parent)
|
||||
LtsMultiRangeSpinBox::LtsMultiRangeSpinBox(QWidget* parent) : QSpinBox(parent)
|
||||
{
|
||||
m_curVal = minimum();
|
||||
|
||||
m_curVal = minimum();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QValidator::State LtsMultiRangeSpinBox::validate(QString &input, int &pos) const
|
||||
QValidator::State LtsMultiRangeSpinBox::validate(QString& input, int& pos) const
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return QValidator::Acceptable;
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::fixup(QString &str) const
|
||||
void LtsMultiRangeSpinBox::fixup(QString& str) const {}
|
||||
|
||||
QValidator::State LtsMultiRangeSpinBox::validateAll(QString& input, int& pos)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
QValidator::State LtsMultiRangeSpinBox::validateAll(QString &input, int &pos)
|
||||
{
|
||||
for(QPair<int,int> range : std::as_const(m_rangesList))
|
||||
{
|
||||
QIntValidator validator(range.first, range.second);
|
||||
QValidator::State valState = validator.validate(input, pos);
|
||||
if (valState == QValidator::Acceptable)
|
||||
for (QPair<int, int> range : std::as_const(m_rangesList))
|
||||
{
|
||||
return valState;
|
||||
QIntValidator validator(range.first, range.second);
|
||||
QValidator::State valState = validator.validate(input, pos);
|
||||
if (valState == QValidator::Acceptable)
|
||||
{
|
||||
return valState;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QValidator::Invalid;
|
||||
|
||||
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
|
||||
QVector<QPair<int,int>> LtsWidgets::LtsMultiRangeSpinBox::sortRanges(const QVector<QPair<int, int> > &ranges)
|
||||
QVector<QPair<int, int>> LtsWidgets::LtsMultiRangeSpinBox::sortRanges(const QVector<QPair<int, int>>& ranges)
|
||||
{
|
||||
QVector<QPair<int, int>> rangesEditable = ranges;
|
||||
QVector<QPair<int, int>> result;
|
||||
std::sort(rangesEditable.begin(), rangesEditable.end());
|
||||
QVector<QPair<int, int>>::iterator it = rangesEditable.begin();
|
||||
QPair<int,int> current = *(it)++;
|
||||
while (it != rangesEditable.end())
|
||||
{
|
||||
if (current.second > it->first)
|
||||
current.second = std::max(current.second, it->second);
|
||||
else
|
||||
QVector<QPair<int, int>> rangesEditable = ranges;
|
||||
QVector<QPair<int, int>> result;
|
||||
std::sort(rangesEditable.begin(), rangesEditable.end());
|
||||
QVector<QPair<int, int>>::iterator it = rangesEditable.begin();
|
||||
QPair<int, int> current = *(it)++;
|
||||
while (it != rangesEditable.end())
|
||||
{
|
||||
result.push_back(current);
|
||||
current = *(it);
|
||||
if (current.second > it->first)
|
||||
current.second = std::max(current.second, it->second);
|
||||
else
|
||||
{
|
||||
result.push_back(current);
|
||||
current = *(it);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
result.push_back(current);
|
||||
return result;
|
||||
result.push_back(current);
|
||||
return result;
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::setRanges(const QVector<QPair<int, int>> &ranges)
|
||||
void LtsMultiRangeSpinBox::setRanges(const QVector<QPair<int, int>>& ranges)
|
||||
{
|
||||
if(ranges.empty())
|
||||
return;
|
||||
if (ranges.empty())
|
||||
return;
|
||||
|
||||
m_rangesList = sortRanges(ranges);
|
||||
m_rangesList = sortRanges(ranges);
|
||||
|
||||
QSpinBox::setMaximum(m_rangesList.last().second);
|
||||
QSpinBox::setMinimum(m_rangesList.first().first);
|
||||
QSpinBox::setMaximum(m_rangesList.last().second);
|
||||
QSpinBox::setMinimum(m_rangesList.first().first);
|
||||
|
||||
QStringList rangeStrings;
|
||||
rangeStrings.reserve(m_rangesList.size());
|
||||
for (const QPair<int,int> &range : std::as_const(m_rangesList))
|
||||
rangeStrings << tr("%1-%2%3").arg(range.first).arg(range.second).arg(suffix());
|
||||
setToolTip(tr("Ranges:\n%1").arg(rangeStrings.join(QStringLiteral(",\n"))));
|
||||
QStringList rangeStrings;
|
||||
rangeStrings.reserve(m_rangesList.size());
|
||||
for (const QPair<int, int>& range : std::as_const(m_rangesList))
|
||||
rangeStrings << tr("%1-%2%3").arg(range.first).arg(range.second).arg(suffix());
|
||||
setToolTip(tr("Ranges:\n%1").arg(rangeStrings.join(QStringLiteral(",\n"))));
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::setRange(int min, int max)
|
||||
{
|
||||
setRanges({{min,max}});
|
||||
setRanges({{min, max}});
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::setMinimum(int min)
|
||||
{
|
||||
auto ranges = m_rangesList;
|
||||
ranges.first().first = min;
|
||||
setRanges(ranges);
|
||||
auto ranges = m_rangesList;
|
||||
ranges.first().first = min;
|
||||
setRanges(ranges);
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::setMaximum(int max)
|
||||
{
|
||||
auto ranges = m_rangesList;
|
||||
ranges.last().second = max;
|
||||
setRanges(ranges);
|
||||
auto ranges = m_rangesList;
|
||||
ranges.last().second = max;
|
||||
setRanges(ranges);
|
||||
}
|
||||
|
||||
int LtsMultiRangeSpinBox::fixupValue(int value) const
|
||||
{
|
||||
|
||||
int nearestValue = INT_MAX;
|
||||
for(QPair<int,int> range : m_rangesList)
|
||||
{
|
||||
if(std::abs(range.first - value) < std::abs(nearestValue - value))
|
||||
nearestValue = range.first;
|
||||
if(std::abs(range.second - value) < std::abs(nearestValue - value))
|
||||
nearestValue = range.second;
|
||||
}
|
||||
value = nearestValue;
|
||||
int buffer = value;
|
||||
int nearestValue = INT_MAX;
|
||||
for (QPair<int, int> range : m_rangesList)
|
||||
{
|
||||
if (std::abs(range.first - value) < std::abs(nearestValue - value))
|
||||
nearestValue = range.first;
|
||||
if (std::abs(range.second - value) < std::abs(nearestValue - value))
|
||||
nearestValue = range.second;
|
||||
}
|
||||
value = nearestValue;
|
||||
int buffer = value;
|
||||
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
{
|
||||
value += singleStep();
|
||||
}
|
||||
value -= remainder;
|
||||
if (2 * remainder > singleStep())
|
||||
{
|
||||
value += singleStep();
|
||||
}
|
||||
value -= remainder;
|
||||
|
||||
if(buffer + singleStep() > value + singleStep())
|
||||
{
|
||||
value+= singleStep();
|
||||
}
|
||||
if (buffer + singleStep() > value + singleStep())
|
||||
{
|
||||
value += singleStep();
|
||||
}
|
||||
|
||||
if (value > maximum())
|
||||
{
|
||||
value -= singleStep();
|
||||
}
|
||||
if (value > maximum())
|
||||
{
|
||||
value -= singleStep();
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
int LtsMultiRangeSpinBox::fixupValue(int value, bool higher) const
|
||||
{
|
||||
|
||||
int nearestValue = INT_MAX;
|
||||
for(QPair<int,int> range : m_rangesList)
|
||||
{
|
||||
if(std::abs(range.first - value) < std::abs(nearestValue - value))
|
||||
int nearestValue = INT_MAX;
|
||||
for (QPair<int, int> range : m_rangesList)
|
||||
{
|
||||
if(higher)
|
||||
{
|
||||
if(range.second < value)
|
||||
continue;
|
||||
if (std::abs(range.first - value) < std::abs(nearestValue - value))
|
||||
{
|
||||
if (higher)
|
||||
{
|
||||
if (range.second < value)
|
||||
continue;
|
||||
}
|
||||
else if (range.second > value)
|
||||
continue;
|
||||
|
||||
} else
|
||||
if(range.second > value)
|
||||
continue;
|
||||
nearestValue = range.first;
|
||||
}
|
||||
if (std::abs(range.second - value) < std::abs(nearestValue - value))
|
||||
{
|
||||
if (higher)
|
||||
{
|
||||
if (range.second < value)
|
||||
continue;
|
||||
}
|
||||
else if (range.second > value)
|
||||
continue;
|
||||
|
||||
nearestValue = range.first;
|
||||
nearestValue = range.second;
|
||||
}
|
||||
}
|
||||
if(std::abs(range.second - value) < std::abs(nearestValue - value))
|
||||
|
||||
value = nearestValue;
|
||||
int curVal = value;
|
||||
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
{
|
||||
if(higher)
|
||||
{
|
||||
if(range.second < value)
|
||||
continue;
|
||||
|
||||
} else
|
||||
if(range.second > value)
|
||||
continue;
|
||||
|
||||
nearestValue = range.second;
|
||||
value += singleStep();
|
||||
}
|
||||
}
|
||||
value -= remainder;
|
||||
|
||||
value = nearestValue;
|
||||
int curVal = value;
|
||||
if (curVal + singleStep() > value + singleStep())
|
||||
{
|
||||
value += singleStep();
|
||||
}
|
||||
if (value > maximum())
|
||||
{
|
||||
value -= singleStep();
|
||||
}
|
||||
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
{
|
||||
value += singleStep();
|
||||
}
|
||||
value -= remainder;
|
||||
|
||||
if(curVal + singleStep() > value + singleStep())
|
||||
{
|
||||
value+= singleStep();
|
||||
}
|
||||
if (value > maximum())
|
||||
{
|
||||
value -= singleStep();
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void LtsMultiRangeSpinBox::focusOutEvent(QFocusEvent *event)
|
||||
void LtsMultiRangeSpinBox::focusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
QSpinBox::focusOutEvent(event);
|
||||
QString value = QString::number(this->value());
|
||||
int length = value.length();
|
||||
QValidator::State valState = validateAll(value, length);
|
||||
QSpinBox::focusOutEvent(event);
|
||||
QString value = QString::number(this->value());
|
||||
int length = value.length();
|
||||
QValidator::State valState = validateAll(value, length);
|
||||
|
||||
if(valState == QValidator::State::Invalid)
|
||||
{
|
||||
this->setValue(fixupValue(value.toInt()));
|
||||
}
|
||||
if (valState == QValidator::State::Invalid)
|
||||
{
|
||||
this->setValue(fixupValue(value.toInt()));
|
||||
}
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::wheelEvent(QWheelEvent *event)
|
||||
void LtsMultiRangeSpinBox::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
QSpinBox::wheelEvent(event);
|
||||
QSpinBox::wheelEvent(event);
|
||||
|
||||
QString valueStr = QString::number(this->value());
|
||||
int length = valueStr.length();
|
||||
QValidator::State valState = validateAll(valueStr, length);
|
||||
QString valueStr = QString::number(this->value());
|
||||
int length = valueStr.length();
|
||||
QValidator::State valState = validateAll(valueStr, length);
|
||||
|
||||
if(valState == QValidator::State::Invalid)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if(this->value() < m_curVal)
|
||||
if (valState == QValidator::State::Invalid)
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), false);
|
||||
setValue(m_curVal);
|
||||
|
||||
if (this->value() < m_curVal)
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), false);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), true);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), true);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::mousePressEvent(QMouseEvent *event)
|
||||
void LtsMultiRangeSpinBox::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QSpinBox::mousePressEvent(event);
|
||||
QString valueStr = QString::number(this->value());
|
||||
int length = valueStr.length();
|
||||
QValidator::State valState = validateAll(valueStr, length);
|
||||
QSpinBox::mousePressEvent(event);
|
||||
QString valueStr = QString::number(this->value());
|
||||
int length = valueStr.length();
|
||||
QValidator::State valState = validateAll(valueStr, length);
|
||||
|
||||
if(valState == QValidator::State::Invalid)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if(this->value() < m_curVal)
|
||||
if (valState == QValidator::State::Invalid)
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), false);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), true);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this->value() < m_curVal)
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), false);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curVal = fixupValue(this->value(), true);
|
||||
setValue(m_curVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LtsMultiRangeSpinBox::keyPressEvent(QKeyEvent *event)
|
||||
void LtsMultiRangeSpinBox::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
QSpinBox::keyPressEvent(event);
|
||||
QString value = QString::number(this->value());
|
||||
int length = value.length();
|
||||
QValidator::State valState = validateAll(value, length);
|
||||
QSpinBox::keyPressEvent(event);
|
||||
QString value = QString::number(this->value());
|
||||
int length = value.length();
|
||||
QValidator::State valState = validateAll(value, length);
|
||||
|
||||
if(valState == QValidator::State::Invalid)
|
||||
{
|
||||
setValue(fixupValue(value.toInt()));
|
||||
}
|
||||
if (valState == QValidator::State::Invalid)
|
||||
{
|
||||
setValue(fixupValue(value.toInt()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+24
-29
@@ -1,51 +1,46 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
#include <QWidget>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <QObject>
|
||||
#include <QPainterPath>
|
||||
#include <QWidget>
|
||||
|
||||
class QPaintEvent;
|
||||
class QResizeEvent;
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class NotiBox;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsNotificationBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class MessageType
|
||||
{
|
||||
Success,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
};
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class MessageType {
|
||||
Success,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
};
|
||||
|
||||
explicit LtsNotificationBox(QWidget *parent = nullptr);
|
||||
explicit LtsNotificationBox(QWidget* parent = nullptr);
|
||||
|
||||
void message(const QString &title, const QString &text, MessageType type = MessageType::Error);
|
||||
void message(const QString& title, const QString& text, MessageType type = MessageType::Error);
|
||||
|
||||
signals:
|
||||
void signalClose();
|
||||
void signalAck();
|
||||
void signalLinkClicked(const QString &link);
|
||||
signals:
|
||||
void signalClose();
|
||||
void signalAck();
|
||||
void signalLinkClicked(const QString& link);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
|
||||
private:
|
||||
Ui::NotiBox *m_ui;
|
||||
QPainterPath roundRectPath;
|
||||
const static int margin;
|
||||
private:
|
||||
Ui::NotiBox* m_ui;
|
||||
QPainterPath roundRectPath;
|
||||
const static int margin;
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+58
-67
@@ -1,114 +1,105 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_operator_menu.h"
|
||||
#include "ui_lts_operator_menu.h"
|
||||
|
||||
#include "lts_info_dialog.h"
|
||||
#include <ngltranslator/ngltranslator.h>
|
||||
#include "ui_lts_operator_menu.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QProcess>
|
||||
#include <QHostInfo>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <ngltranslator/ngltranslator.h>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsOperatorMenu::LtsOperatorMenu(const QString &operatorName, const QString &workspaceId, bool debug, int screenCount, QWidget *parent)
|
||||
: LtsFramelessDialog(parent)
|
||||
, m_ui(new Ui::LtsOperatorMenu)
|
||||
LtsOperatorMenu::LtsOperatorMenu(const QString& operatorName, const QString& workspaceId, bool debug, int screenCount,
|
||||
QWidget* parent)
|
||||
: LtsFramelessDialog(parent), m_ui(new Ui::LtsOperatorMenu)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->lbOperatorName->setText(operatorName);
|
||||
m_ui->lbHostName->setText(QHostInfo::localHostName());
|
||||
m_ui->setupUi(this);
|
||||
m_ui->lbOperatorName->setText(operatorName);
|
||||
m_ui->lbHostName->setText(QHostInfo::localHostName());
|
||||
|
||||
if (screenCount < 2)
|
||||
m_ui->pbSwap->hide();
|
||||
if (screenCount < 2)
|
||||
m_ui->pbSwap->hide();
|
||||
|
||||
if (debug)
|
||||
m_ui->lbWorkspaceId->setText(tr("Workspace: >>>%1<<<").arg(workspaceId));
|
||||
else
|
||||
m_ui->lbWorkspaceId->hide();
|
||||
if (debug)
|
||||
m_ui->lbWorkspaceId->setText(tr("Workspace: >>>%1<<<").arg(workspaceId));
|
||||
else
|
||||
m_ui->lbWorkspaceId->hide();
|
||||
|
||||
connect(m_ui->pbOperatorSettings, &QPushButton::clicked, this, &LtsOperatorMenu::signalShowOperatorSettings);
|
||||
connect(m_ui->pbOperatorSettings, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbWindow, &QPushButton::clicked, this, &LtsOperatorMenu::onTerminalButtonClicked);
|
||||
connect(m_ui->pbWindow, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbLogout, &QPushButton::clicked, this, &LtsOperatorMenu::signalLogout);
|
||||
connect(m_ui->pbExit, &QPushButton::clicked, this, &LtsOperatorMenu::signalExit);
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbSwap, &QPushButton::clicked, this, &LtsOperatorMenu::signalSwap);
|
||||
connect(m_ui->pbSwap, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbAbout, &QPushButton::clicked, this, &LtsOperatorMenu::slotShowInfoDialog);
|
||||
connect(m_ui->pbAbout, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbOperatorSettings, &QPushButton::clicked, this, &LtsOperatorMenu::signalShowOperatorSettings);
|
||||
connect(m_ui->pbOperatorSettings, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbWindow, &QPushButton::clicked, this, &LtsOperatorMenu::onTerminalButtonClicked);
|
||||
connect(m_ui->pbWindow, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbLogout, &QPushButton::clicked, this, &LtsOperatorMenu::signalLogout);
|
||||
connect(m_ui->pbExit, &QPushButton::clicked, this, &LtsOperatorMenu::signalExit);
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbSwap, &QPushButton::clicked, this, &LtsOperatorMenu::signalSwap);
|
||||
connect(m_ui->pbSwap, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
connect(m_ui->pbAbout, &QPushButton::clicked, this, &LtsOperatorMenu::slotShowInfoDialog);
|
||||
connect(m_ui->pbAbout, &QPushButton::clicked, this, &LtsOperatorMenu::close);
|
||||
|
||||
if (NGL::translationLocale() == "de_DE")
|
||||
m_ui->pbGer->setChecked(true);
|
||||
else
|
||||
m_ui->pbInt->setChecked(true);
|
||||
|
||||
if (NGL::translationLocale() == "de_DE")
|
||||
m_ui->pbGer->setChecked(true);
|
||||
else
|
||||
m_ui->pbInt->setChecked(true);
|
||||
|
||||
connect(m_ui->pbGer, &QPushButton::clicked,
|
||||
this, &LtsOperatorMenu::onLanguageChange);
|
||||
connect(m_ui->pbInt, &QPushButton::clicked,
|
||||
this, &LtsOperatorMenu::onLanguageChange);
|
||||
connect(m_ui->pbGer, &QPushButton::clicked, this, &LtsOperatorMenu::onLanguageChange);
|
||||
connect(m_ui->pbInt, &QPushButton::clicked, this, &LtsOperatorMenu::onLanguageChange);
|
||||
|
||||
#ifndef LTS_DEBUG
|
||||
m_ui->debugWidget->hide();
|
||||
m_ui->debugWidget->hide();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
LtsOperatorMenu::~LtsOperatorMenu()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void LtsOperatorMenu::slotShowInfoDialog()
|
||||
{
|
||||
LtsInfoDialog *infoDialog = new LtsInfoDialog();
|
||||
infoDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
infoDialog->show();
|
||||
LtsInfoDialog* infoDialog = new LtsInfoDialog();
|
||||
infoDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
infoDialog->show();
|
||||
}
|
||||
|
||||
|
||||
void LtsOperatorMenu::onTerminalButtonClicked()
|
||||
{
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
QString lang = QString::fromLatin1(NGL::translationLocale());
|
||||
lang.append(QStringLiteral(".UTF-8"));
|
||||
env.insert(QStringLiteral("LANG"), lang);
|
||||
QString lang = QString::fromLatin1(NGL::translationLocale());
|
||||
lang.append(QStringLiteral(".UTF-8"));
|
||||
env.insert(QStringLiteral("LANG"), lang);
|
||||
|
||||
QProcess process;
|
||||
process.setProcessEnvironment(env);
|
||||
QStringList args;
|
||||
args << QStringLiteral("--geometry") << QStringLiteral("800x800+200+100");
|
||||
QProcess process;
|
||||
process.setProcessEnvironment(env);
|
||||
QStringList args;
|
||||
args << QStringLiteral("--geometry") << QStringLiteral("800x800+200+100");
|
||||
|
||||
if (QApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
||||
process.startDetached(QStringLiteral("xterm"), args);
|
||||
else
|
||||
process.startDetached(QStringLiteral("konsole"), args);
|
||||
if (QApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
||||
process.startDetached(QStringLiteral("xterm"), args);
|
||||
else
|
||||
process.startDetached(QStringLiteral("konsole"), args);
|
||||
}
|
||||
|
||||
|
||||
void LtsOperatorMenu::setTerminalButton(bool bVisible)
|
||||
{
|
||||
m_ui->pbWindow->setVisible(bVisible);
|
||||
m_ui->pbWindow->setVisible(bVisible);
|
||||
}
|
||||
|
||||
void LtsOperatorMenu::setOperatorSettingsButton(bool bVisible)
|
||||
{
|
||||
m_ui->pbOperatorSettings->setVisible(bVisible);
|
||||
m_ui->pbOperatorSettings->setVisible(bVisible);
|
||||
}
|
||||
|
||||
|
||||
void LtsOperatorMenu::onLanguageChange()
|
||||
{
|
||||
if (m_ui->pbGer->isChecked())
|
||||
NGL::setTranslationLocale(QByteArray("de_DE"));
|
||||
if (m_ui->pbGer->isChecked())
|
||||
NGL::setTranslationLocale(QByteArray("de_DE"));
|
||||
|
||||
if (m_ui->pbInt->isChecked())
|
||||
NGL::setTranslationLocale(QByteArray("en_GB"));
|
||||
if (m_ui->pbInt->isChecked())
|
||||
NGL::setTranslationLocale(QByteArray("en_GB"));
|
||||
}
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+22
-22
@@ -1,14 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_frameless_dialog.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class LtsOperatorMenu;
|
||||
}
|
||||
|
||||
@@ -16,28 +15,29 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsOperatorMenu : public LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsOperatorMenu(const QString &operatorName, const QString &workspaceId, bool debug, int screenCount, QWidget *parent);
|
||||
~LtsOperatorMenu();
|
||||
public:
|
||||
explicit LtsOperatorMenu(const QString& operatorName, const QString& workspaceId, bool debug, int screenCount,
|
||||
QWidget* parent);
|
||||
~LtsOperatorMenu();
|
||||
|
||||
void setTerminalButton(bool bVisible);
|
||||
void setOperatorSettingsButton(bool bVisible);
|
||||
void setTerminalButton(bool bVisible);
|
||||
void setOperatorSettingsButton(bool bVisible);
|
||||
|
||||
private:
|
||||
Ui::LtsOperatorMenu *m_ui;
|
||||
private:
|
||||
Ui::LtsOperatorMenu* m_ui;
|
||||
|
||||
signals:
|
||||
void signalLogout();
|
||||
void signalExit();
|
||||
void signalShowOperatorSettings();
|
||||
void signalSwap();
|
||||
signals:
|
||||
void signalLogout();
|
||||
void signalExit();
|
||||
void signalShowOperatorSettings();
|
||||
void signalSwap();
|
||||
|
||||
private slots:
|
||||
void onTerminalButtonClicked();
|
||||
void onLanguageChange();
|
||||
void slotShowInfoDialog();
|
||||
private slots:
|
||||
void onTerminalButtonClicked();
|
||||
void onLanguageChange();
|
||||
void slotShowInfoDialog();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+11
-19
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_overlay_loading.h"
|
||||
|
||||
#include "ui_lts_overlay_loading.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
@@ -9,37 +9,29 @@
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsOverlayLoading::LtsOverlayLoading(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::LtsOverlayLoading)
|
||||
LtsOverlayLoading::LtsOverlayLoading(QWidget* parent) : QWidget(parent), m_ui(new Ui::LtsOverlayLoading)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setCancelButtonVisible(false);
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked,
|
||||
this, [this](){ setCancelButtonEnabled(false); });
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked,
|
||||
this, &LtsOverlayLoading::cancel);
|
||||
m_ui->setupUi(this);
|
||||
setCancelButtonVisible(false);
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, [this]() { setCancelButtonEnabled(false); });
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, &LtsOverlayLoading::cancel);
|
||||
}
|
||||
|
||||
|
||||
void LtsOverlayLoading::setText(const QString &text)
|
||||
void LtsOverlayLoading::setText(const QString& text)
|
||||
{
|
||||
m_ui->label->setText(text);
|
||||
m_ui->label->setText(text);
|
||||
}
|
||||
|
||||
|
||||
void LtsOverlayLoading::setCancelButtonVisible(bool visible)
|
||||
{
|
||||
m_ui->pbCancel->setVisible(visible);
|
||||
m_ui->pbCancel->setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
void LtsOverlayLoading::setCancelButtonEnabled(bool enabled)
|
||||
{
|
||||
m_ui->pbCancel->setEnabled(enabled);
|
||||
m_ui->pbCancel->setEnabled(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+16
-18
@@ -1,35 +1,33 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui { class LtsOverlayLoading; }
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsOverlayLoading;
|
||||
}
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsOverlayLoading : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsOverlayLoading(QWidget *parent = nullptr);
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsOverlayLoading(QWidget* parent = nullptr);
|
||||
|
||||
void setText(const QString &text);
|
||||
void setCancelButtonVisible(bool visible);
|
||||
void setCancelButtonEnabled(bool enabled);
|
||||
void setText(const QString& text);
|
||||
void setCancelButtonVisible(bool visible);
|
||||
void setCancelButtonEnabled(bool enabled);
|
||||
|
||||
signals:
|
||||
void cancel();
|
||||
signals:
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
Ui::LtsOverlayLoading *m_ui;
|
||||
private:
|
||||
Ui::LtsOverlayLoading* m_ui;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+254
-259
@@ -1,339 +1,334 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_picture_view.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsColorizeEffect>
|
||||
#include <QRubberBand>
|
||||
|
||||
#include <QGraphicsColorizeEffect>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QMouseEvent>
|
||||
#include <QRubberBand>
|
||||
|
||||
using namespace LtsWidgets;
|
||||
|
||||
LtsPictureView::LtsPictureView(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
, m_gsPicture(new QGraphicsScene(this))
|
||||
, m_rubberband(new QRubberBand(QRubberBand::Rectangle, this))
|
||||
, m_image(nullptr)
|
||||
, m_origimage(nullptr)
|
||||
LtsPictureView::LtsPictureView(QWidget* parent)
|
||||
: QGraphicsView(parent), m_gsPicture(new QGraphicsScene(this)),
|
||||
m_rubberband(new QRubberBand(QRubberBand::Rectangle, this)), m_image(nullptr), m_origimage(nullptr)
|
||||
{
|
||||
m_mouseActive = false;
|
||||
m_moveable = false;
|
||||
m_aspectRatioEnabled = true;
|
||||
m_s_inEdit = false;
|
||||
m_mouseActive = false;
|
||||
m_moveable = false;
|
||||
m_aspectRatioEnabled = true;
|
||||
m_s_inEdit = false;
|
||||
|
||||
m_aspectRatio = 1;
|
||||
m_aspectRatio = 1;
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
|
||||
LtsPictureView::~LtsPictureView()
|
||||
{
|
||||
delete m_rubberband;
|
||||
delete m_rubberband;
|
||||
}
|
||||
|
||||
void LtsPictureView::setAspectRatio(double aspectRatio)
|
||||
{
|
||||
m_aspectRatio = aspectRatio;
|
||||
newRubberBand();
|
||||
m_aspectRatio = aspectRatio;
|
||||
newRubberBand();
|
||||
}
|
||||
|
||||
void LtsPictureView::ratioClicked(bool enabled)
|
||||
{
|
||||
m_aspectRatioEnabled = enabled;
|
||||
if (enabled)
|
||||
newRubberBand();
|
||||
m_aspectRatioEnabled = enabled;
|
||||
if (enabled)
|
||||
newRubberBand();
|
||||
}
|
||||
|
||||
void LtsPictureView::mousePressEvent(QMouseEvent *event)
|
||||
void LtsPictureView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if (m_rubberband->geometry().contains(event->pos()))
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_bandoffset = event->pos() - m_rubberband->pos();
|
||||
m_moveable = true;
|
||||
m_rubberband->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_origin = event->pos();
|
||||
m_curRectangle = QRect(m_origin.x(), m_origin.y(), 0, 0);
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
m_rubberband->show();
|
||||
m_mouseActive = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hideRubberband();
|
||||
newRubberBand();
|
||||
m_mouseActive = false;
|
||||
}
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void LtsPictureView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_moveable == true)
|
||||
{
|
||||
QPoint newCoord = event->pos() - m_bandoffset;
|
||||
if (newCoord.x() < 0)
|
||||
newCoord.setX(0);
|
||||
if (newCoord.y() < 0)
|
||||
newCoord.setY(0);
|
||||
if (m_origimage->pixmap().width() < (newCoord.x() + m_rubberband->width()))
|
||||
newCoord.setX(m_origimage->pixmap().width() - m_rubberband->width() + 1);
|
||||
if (m_origimage->pixmap().height() < (newCoord.y() + m_rubberband->height()))
|
||||
newCoord.setY(m_origimage->pixmap().height() - m_rubberband->height() + 1);
|
||||
m_rubberband->move(newCoord);
|
||||
QPoint move = m_rubberband->pos();
|
||||
int left = move.x();
|
||||
int top = move.y();
|
||||
int width = m_rubberband->rect().width();
|
||||
int height = m_rubberband->rect().height();
|
||||
emit mouseMoved(QRect(left, top, width, height));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_mouseActive)
|
||||
{
|
||||
QRect rect;
|
||||
|
||||
int xMax = event->pos().x();
|
||||
int yMax = event->pos().y();
|
||||
|
||||
if (event->pos().x() > m_origimage->pixmap().width())
|
||||
xMax = m_origimage->pixmap().width();
|
||||
if (event->pos().x() < 0)
|
||||
xMax = 0;
|
||||
if (event->pos().y() > m_origimage->pixmap().height())
|
||||
yMax = m_origimage->pixmap().height();
|
||||
if (event->pos().y() < 0)
|
||||
yMax = 0;
|
||||
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
const int xMin = m_origin.x();
|
||||
const int yMin = m_origin.y();
|
||||
|
||||
int xLengthAbs(std::abs(xMax - xMin));
|
||||
int yLengthAbs(std::abs(yMax - yMin));
|
||||
|
||||
QPoint length;
|
||||
|
||||
if (xLengthAbs / m_aspectRatio > yLengthAbs * m_aspectRatio)
|
||||
if (m_rubberband->geometry().contains(event->pos()))
|
||||
{
|
||||
length.setX(xLengthAbs);
|
||||
length.setY(length.x() / m_aspectRatio);
|
||||
m_bandoffset = event->pos() - m_rubberband->pos();
|
||||
m_moveable = true;
|
||||
m_rubberband->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
length.setY(yLengthAbs);
|
||||
length.setX(length.y() * m_aspectRatio);
|
||||
m_origin = event->pos();
|
||||
m_curRectangle = QRect(m_origin.x(), m_origin.y(), 0, 0);
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
m_rubberband->show();
|
||||
m_mouseActive = true;
|
||||
}
|
||||
|
||||
if (!(yMax - yMin < 0) && length.y() + m_origin.y() > m_origimage->pixmap().height())
|
||||
{
|
||||
length.setY(m_origimage->pixmap().height() - m_origin.y());
|
||||
length.setX(length.y()* m_aspectRatio);
|
||||
}
|
||||
if (!(xMax - xMin < 0) && length.x() + m_origin.x() > m_origimage->pixmap().width())
|
||||
{
|
||||
length.setX(m_origimage->pixmap().width() - m_origin.x());
|
||||
length.setY(length.x() / m_aspectRatio);
|
||||
}
|
||||
|
||||
if (xMax - xMin < 0)
|
||||
{
|
||||
length.setX(length.x() * -1);
|
||||
if (length.x() + m_origin.x() < 0)
|
||||
{
|
||||
length.setX(0 - m_origin.x());
|
||||
length.setY((length.x() / m_aspectRatio) * -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (yMax - yMin < 0)
|
||||
{
|
||||
length.setY(length.y() * -1);
|
||||
if (length.y() + m_origin.y() < 0)
|
||||
{
|
||||
length.setY(0 - m_origin.y());
|
||||
length.setX(length.y() * m_aspectRatio);
|
||||
if (!(xMax - xMin < 0))
|
||||
length.setX(length.x() * -1);
|
||||
}
|
||||
}
|
||||
|
||||
length = m_origin + length;
|
||||
rect.setTopLeft(m_origin);
|
||||
rect.setBottomRight(length);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.setTopLeft(m_origin);
|
||||
rect.setBottomRight(QPoint(xMax, yMax));
|
||||
}
|
||||
m_curRectangle = rect.normalized();
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
}
|
||||
}
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
else
|
||||
{
|
||||
hideRubberband();
|
||||
newRubberBand();
|
||||
m_mouseActive = false;
|
||||
}
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void LtsPictureView::mouseReleaseEvent(QMouseEvent *event)
|
||||
void LtsPictureView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
m_moveable = false;
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
if (m_moveable == true)
|
||||
{
|
||||
QPoint newCoord = event->pos() - m_bandoffset;
|
||||
if (newCoord.x() < 0)
|
||||
newCoord.setX(0);
|
||||
if (newCoord.y() < 0)
|
||||
newCoord.setY(0);
|
||||
if (m_origimage->pixmap().width() < (newCoord.x() + m_rubberband->width()))
|
||||
newCoord.setX(m_origimage->pixmap().width() - m_rubberband->width() + 1);
|
||||
if (m_origimage->pixmap().height() < (newCoord.y() + m_rubberband->height()))
|
||||
newCoord.setY(m_origimage->pixmap().height() - m_rubberband->height() + 1);
|
||||
m_rubberband->move(newCoord);
|
||||
QPoint move = m_rubberband->pos();
|
||||
int left = move.x();
|
||||
int top = move.y();
|
||||
int width = m_rubberband->rect().width();
|
||||
int height = m_rubberband->rect().height();
|
||||
emit mouseMoved(QRect(left, top, width, height));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_mouseActive)
|
||||
{
|
||||
QRect rect;
|
||||
|
||||
int xMax = event->pos().x();
|
||||
int yMax = event->pos().y();
|
||||
|
||||
if (event->pos().x() > m_origimage->pixmap().width())
|
||||
xMax = m_origimage->pixmap().width();
|
||||
if (event->pos().x() < 0)
|
||||
xMax = 0;
|
||||
if (event->pos().y() > m_origimage->pixmap().height())
|
||||
yMax = m_origimage->pixmap().height();
|
||||
if (event->pos().y() < 0)
|
||||
yMax = 0;
|
||||
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
const int xMin = m_origin.x();
|
||||
const int yMin = m_origin.y();
|
||||
|
||||
int xLengthAbs(std::abs(xMax - xMin));
|
||||
int yLengthAbs(std::abs(yMax - yMin));
|
||||
|
||||
QPoint length;
|
||||
|
||||
if (xLengthAbs / m_aspectRatio > yLengthAbs * m_aspectRatio)
|
||||
{
|
||||
length.setX(xLengthAbs);
|
||||
length.setY(length.x() / m_aspectRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
length.setY(yLengthAbs);
|
||||
length.setX(length.y() * m_aspectRatio);
|
||||
}
|
||||
|
||||
if (!(yMax - yMin < 0) && length.y() + m_origin.y() > m_origimage->pixmap().height())
|
||||
{
|
||||
length.setY(m_origimage->pixmap().height() - m_origin.y());
|
||||
length.setX(length.y() * m_aspectRatio);
|
||||
}
|
||||
if (!(xMax - xMin < 0) && length.x() + m_origin.x() > m_origimage->pixmap().width())
|
||||
{
|
||||
length.setX(m_origimage->pixmap().width() - m_origin.x());
|
||||
length.setY(length.x() / m_aspectRatio);
|
||||
}
|
||||
|
||||
if (xMax - xMin < 0)
|
||||
{
|
||||
length.setX(length.x() * -1);
|
||||
if (length.x() + m_origin.x() < 0)
|
||||
{
|
||||
length.setX(0 - m_origin.x());
|
||||
length.setY((length.x() / m_aspectRatio) * -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (yMax - yMin < 0)
|
||||
{
|
||||
length.setY(length.y() * -1);
|
||||
if (length.y() + m_origin.y() < 0)
|
||||
{
|
||||
length.setY(0 - m_origin.y());
|
||||
length.setX(length.y() * m_aspectRatio);
|
||||
if (!(xMax - xMin < 0))
|
||||
length.setX(length.x() * -1);
|
||||
}
|
||||
}
|
||||
|
||||
length = m_origin + length;
|
||||
rect.setTopLeft(m_origin);
|
||||
rect.setBottomRight(length);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.setTopLeft(m_origin);
|
||||
rect.setBottomRight(QPoint(xMax, yMax));
|
||||
}
|
||||
m_curRectangle = rect.normalized();
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
}
|
||||
}
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void LtsPictureView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
m_moveable = false;
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void LtsPictureView::hideRubberband()
|
||||
{
|
||||
m_rubberband->hide();
|
||||
m_rubberband->hide();
|
||||
}
|
||||
|
||||
void LtsPictureView::newRubberBand()
|
||||
{
|
||||
delete m_rubberband;
|
||||
m_rubberband = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
delete m_rubberband;
|
||||
m_rubberband = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
}
|
||||
|
||||
void LtsPictureView::setPicture(const QImage &image, const QPoint &pos, const bool flag)
|
||||
void LtsPictureView::setPicture(const QImage& image, const QPoint& pos, const bool flag)
|
||||
{
|
||||
if (m_image)
|
||||
{
|
||||
m_gsPicture->removeItem(m_image);
|
||||
delete m_image;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (m_origimage)
|
||||
if (m_image)
|
||||
{
|
||||
m_gsPicture->removeItem(m_origimage);
|
||||
delete m_origimage;
|
||||
m_gsPicture->removeItem(m_image);
|
||||
delete m_image;
|
||||
}
|
||||
QGraphicsOpacityEffect *opacity = new QGraphicsOpacityEffect;
|
||||
opacity->setOpacity(0.2);
|
||||
if (flag)
|
||||
{
|
||||
if (m_origimage)
|
||||
{
|
||||
m_gsPicture->removeItem(m_origimage);
|
||||
delete m_origimage;
|
||||
}
|
||||
QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect;
|
||||
opacity->setOpacity(0.2);
|
||||
|
||||
m_origimage = new QGraphicsPixmapItem(QPixmap::fromImage(image));
|
||||
m_origimage->setGraphicsEffect(opacity);
|
||||
m_origimage = new QGraphicsPixmapItem(QPixmap::fromImage(image));
|
||||
m_origimage->setGraphicsEffect(opacity);
|
||||
|
||||
m_gsPicture->addItem(m_origimage);
|
||||
m_gsPicture->addItem(m_origimage);
|
||||
|
||||
setMinimumSize(image.size());
|
||||
setMaximumSize(image.size());
|
||||
emit setLimits(m_origimage->pixmap().size(), true);
|
||||
}
|
||||
m_image = new QGraphicsPixmapItem(QPixmap::fromImage(image));
|
||||
setMinimumSize(image.size());
|
||||
setMaximumSize(image.size());
|
||||
emit setLimits(m_origimage->pixmap().size(), true);
|
||||
}
|
||||
m_image = new QGraphicsPixmapItem(QPixmap::fromImage(image));
|
||||
|
||||
m_image->setPos(pos);
|
||||
m_gsPicture->addItem(m_image);
|
||||
setScene(m_gsPicture);
|
||||
m_image->setPos(pos);
|
||||
m_gsPicture->addItem(m_image);
|
||||
setScene(m_gsPicture);
|
||||
}
|
||||
|
||||
void LtsPictureView::leftChanged(int left)
|
||||
{
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setLeft(left);
|
||||
if(m_aspectRatioEnabled)
|
||||
{
|
||||
int newHeight = m_curRectangle.width() / m_aspectRatio;
|
||||
if (m_origin.y() < m_curRectangle.bottom())
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setLeft(left);
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
m_curRectangle.setHeight(newHeight);
|
||||
int newHeight = m_curRectangle.width() / m_aspectRatio;
|
||||
if (m_origin.y() < m_curRectangle.bottom())
|
||||
{
|
||||
m_curRectangle.setHeight(newHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.height() - newHeight;
|
||||
m_curRectangle.setTop(m_curRectangle.top() + offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.height() - newHeight;
|
||||
m_curRectangle.setTop(m_curRectangle.top() + offset);
|
||||
}
|
||||
}
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
}
|
||||
|
||||
void LtsPictureView::rightChanged(int right)
|
||||
{
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setRight(right);
|
||||
if(m_aspectRatioEnabled)
|
||||
{
|
||||
int newHeight = m_curRectangle.width() / m_aspectRatio;
|
||||
if (m_origin.y() < m_curRectangle.bottom())
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setRight(right);
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
m_curRectangle.setHeight(newHeight);
|
||||
int newHeight = m_curRectangle.width() / m_aspectRatio;
|
||||
if (m_origin.y() < m_curRectangle.bottom())
|
||||
{
|
||||
m_curRectangle.setHeight(newHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.height() - newHeight;
|
||||
m_curRectangle.setTop(m_curRectangle.top() + offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.height() - newHeight;
|
||||
m_curRectangle.setTop(m_curRectangle.top() + offset);
|
||||
}
|
||||
}
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
}
|
||||
|
||||
void LtsPictureView::topChanged(int top)
|
||||
{
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setTop(top);
|
||||
if(m_aspectRatioEnabled)
|
||||
{
|
||||
int newWidth = m_curRectangle.height() * m_aspectRatio;
|
||||
if (m_origin.x() <= m_curRectangle.left())
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setTop(top);
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
m_curRectangle.setWidth(newWidth);
|
||||
int newWidth = m_curRectangle.height() * m_aspectRatio;
|
||||
if (m_origin.x() <= m_curRectangle.left())
|
||||
{
|
||||
m_curRectangle.setWidth(newWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.width() - newWidth;
|
||||
m_curRectangle.setLeft(m_curRectangle.left() + offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.width() - newWidth;
|
||||
m_curRectangle.setLeft(m_curRectangle.left() + offset);
|
||||
}
|
||||
}
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
}
|
||||
|
||||
void LtsPictureView::bottomChanged(int bottom)
|
||||
{
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setBottom(bottom);
|
||||
if(m_aspectRatioEnabled)
|
||||
{
|
||||
int newWidth = m_curRectangle.height() * m_aspectRatio;
|
||||
if (m_origin.x() <= m_curRectangle.left())
|
||||
if (m_s_inEdit || m_mouseActive)
|
||||
return;
|
||||
m_s_inEdit = true;
|
||||
m_curRectangle.setBottom(bottom);
|
||||
if (m_aspectRatioEnabled)
|
||||
{
|
||||
m_curRectangle.setWidth(newWidth);
|
||||
int newWidth = m_curRectangle.height() * m_aspectRatio;
|
||||
if (m_origin.x() <= m_curRectangle.left())
|
||||
{
|
||||
m_curRectangle.setWidth(newWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.width() - newWidth;
|
||||
m_curRectangle.setLeft(m_curRectangle.left() + offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = m_curRectangle.width() - newWidth;
|
||||
m_curRectangle.setLeft(m_curRectangle.left() + offset);
|
||||
}
|
||||
}
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
m_rubberband->setGeometry(m_curRectangle);
|
||||
emit mouseMoved(m_curRectangle);
|
||||
m_s_inEdit = false;
|
||||
}
|
||||
|
||||
|
||||
QGraphicsPixmapItem *LtsPictureView::getImage()
|
||||
QGraphicsPixmapItem* LtsPictureView::getImage()
|
||||
{
|
||||
if (!m_image)
|
||||
m_image = new QGraphicsPixmapItem;
|
||||
return m_image;
|
||||
if (!m_image)
|
||||
m_image = new QGraphicsPixmapItem;
|
||||
return m_image;
|
||||
}
|
||||
Executable → Regular
+39
-40
@@ -1,11 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QObject>
|
||||
|
||||
class QRubberBand;
|
||||
|
||||
@@ -13,49 +12,49 @@ namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsPictureView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsPictureView(QWidget *parent = nullptr);
|
||||
~LtsPictureView();
|
||||
void hideRubberband();
|
||||
void newRubberBand();
|
||||
void cutPicture();
|
||||
QGraphicsPixmapItem *getImage();
|
||||
public:
|
||||
explicit LtsPictureView(QWidget* parent = nullptr);
|
||||
~LtsPictureView();
|
||||
void hideRubberband();
|
||||
void newRubberBand();
|
||||
void cutPicture();
|
||||
QGraphicsPixmapItem* getImage();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
bool m_mouseActive;
|
||||
bool m_moveable;
|
||||
bool m_aspectRatioEnabled;
|
||||
bool m_s_inEdit;
|
||||
private:
|
||||
bool m_mouseActive;
|
||||
bool m_moveable;
|
||||
bool m_aspectRatioEnabled;
|
||||
bool m_s_inEdit;
|
||||
|
||||
double m_aspectRatio;
|
||||
QRect m_curRectangle;
|
||||
double m_aspectRatio;
|
||||
QRect m_curRectangle;
|
||||
|
||||
QGraphicsScene *m_gsPicture;
|
||||
QRubberBand *m_rubberband;
|
||||
QGraphicsPixmapItem *m_image;
|
||||
QGraphicsPixmapItem *m_origimage;
|
||||
QGraphicsScene* m_gsPicture;
|
||||
QRubberBand* m_rubberband;
|
||||
QGraphicsPixmapItem* m_image;
|
||||
QGraphicsPixmapItem* m_origimage;
|
||||
|
||||
QPoint m_origin;
|
||||
QPoint m_bandoffset;
|
||||
QPoint m_origin;
|
||||
QPoint m_bandoffset;
|
||||
|
||||
public slots:
|
||||
void setPicture(const QImage &image, const QPoint &pos, const bool flag);
|
||||
void setAspectRatio(double aspectRatio);
|
||||
void ratioClicked(bool enabled);
|
||||
void leftChanged(int left);
|
||||
void rightChanged(int right);
|
||||
void topChanged(int top);
|
||||
void bottomChanged(int bottom);
|
||||
public slots:
|
||||
void setPicture(const QImage& image, const QPoint& pos, const bool flag);
|
||||
void setAspectRatio(double aspectRatio);
|
||||
void ratioClicked(bool enabled);
|
||||
void leftChanged(int left);
|
||||
void rightChanged(int right);
|
||||
void topChanged(int top);
|
||||
void bottomChanged(int bottom);
|
||||
|
||||
signals:
|
||||
void mouseMoved(const QRect &);
|
||||
void setLimits(const QSize &, bool);
|
||||
signals:
|
||||
void mouseMoved(const QRect&);
|
||||
void setLimits(const QSize&, bool);
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+31
-32
@@ -1,56 +1,55 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsProfileButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QPixmap pixMap READ pixmap WRITE setPixmap )
|
||||
Q_PROPERTY( bool menuEnabled READ menuEnabled WRITE setMenuEnabled )
|
||||
Q_PROPERTY(QPixmap pixMap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(bool menuEnabled READ menuEnabled WRITE setMenuEnabled)
|
||||
|
||||
public:
|
||||
explicit LtsProfileButton(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit LtsProfileButton(QWidget* parent = nullptr);
|
||||
|
||||
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
const QPixmap& pixmap() const
|
||||
{
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
const QPixmap &pixmap() const { return m_pixmap; }
|
||||
void setMenuEnabled(bool enabled = true)
|
||||
{
|
||||
m_menuEnabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
bool menuEnabled() const
|
||||
{
|
||||
return m_menuEnabled;
|
||||
}
|
||||
|
||||
void setMenuEnabled(bool enabled = true) { m_menuEnabled = enabled; }
|
||||
bool menuEnabled() const { return m_menuEnabled; }
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void enterEvent(QEvent* event);
|
||||
void leaveEvent(QEvent* event);
|
||||
bool event(QEvent* event);
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
bool m_isHovered;
|
||||
bool m_menuEnabled;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
bool event(QEvent *event);
|
||||
signals:
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
bool m_isHovered;
|
||||
bool m_menuEnabled;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
void signalClicked();
|
||||
void signalClicked();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+74
-93
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_progress_dialog_helper.h"
|
||||
|
||||
#include "lts_frameless_dialog.h"
|
||||
@@ -12,136 +11,118 @@
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsProgressDialogHelper::LtsProgressDialogHelper(QWidget *parent)
|
||||
: QObject(parent)
|
||||
, m_waitDlg(nullptr)
|
||||
, m_parentWidget(parent)
|
||||
, m_textLabel(nullptr)
|
||||
{}
|
||||
|
||||
LtsProgressDialogHelper::LtsProgressDialogHelper(QWidget* parent)
|
||||
: QObject(parent), m_waitDlg(nullptr), m_parentWidget(parent), m_textLabel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
LtsProgressDialogHelper::~LtsProgressDialogHelper()
|
||||
{
|
||||
delete m_waitDlg;
|
||||
delete m_waitDlg;
|
||||
}
|
||||
|
||||
|
||||
void LtsProgressDialogHelper::setCustomText(const QString &customText)
|
||||
void LtsProgressDialogHelper::setCustomText(const QString& customText)
|
||||
{
|
||||
if (m_waitDlg == nullptr || m_textLabel == nullptr)
|
||||
return;
|
||||
if (m_waitDlg == nullptr || m_textLabel == nullptr)
|
||||
return;
|
||||
|
||||
if (customText.isEmpty())
|
||||
m_textLabel->setText(tr("Waiting for server reply..."));
|
||||
else
|
||||
m_textLabel->setText(customText);
|
||||
if (customText.isEmpty())
|
||||
m_textLabel->setText(tr("Waiting for server reply..."));
|
||||
else
|
||||
m_textLabel->setText(customText);
|
||||
}
|
||||
|
||||
void LtsProgressDialogHelper::setParentWidget(QWidget *newParent)
|
||||
void LtsProgressDialogHelper::setParentWidget(QWidget* newParent)
|
||||
{
|
||||
m_parentWidget = newParent;
|
||||
if (m_waitDlg)
|
||||
{
|
||||
m_waitDlg->setParent(newParent);
|
||||
QTimer::singleShot(0, m_waitDlg.data(), &LtsFramelessDialog::onUpdateGeometry);
|
||||
}
|
||||
m_parentWidget = newParent;
|
||||
if (m_waitDlg)
|
||||
{
|
||||
m_waitDlg->setParent(newParent);
|
||||
QTimer::singleShot(0, m_waitDlg.data(), &LtsFramelessDialog::onUpdateGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsProgressDialogHelper::slotShowWaitForReplyWindow()
|
||||
{
|
||||
if (m_waitDlg)
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
||||
if (m_waitDlg)
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
||||
|
||||
QHBoxLayout *l = new QHBoxLayout(m_waitDlg);
|
||||
QHBoxLayout* l = new QHBoxLayout(m_waitDlg);
|
||||
|
||||
QProgressBar *pb = new QProgressBar(m_waitDlg);
|
||||
pb->setMaximum(0);
|
||||
pb->setValue(-1);
|
||||
QProgressBar* pb = new QProgressBar(m_waitDlg);
|
||||
pb->setMaximum(0);
|
||||
pb->setValue(-1);
|
||||
|
||||
l->addWidget(pb);
|
||||
l->addWidget(pb);
|
||||
|
||||
m_textLabel = new QLabel(m_waitDlg);
|
||||
setCustomText();
|
||||
l->addWidget(m_textLabel);
|
||||
m_textLabel = new QLabel(m_waitDlg);
|
||||
setCustomText();
|
||||
l->addWidget(m_textLabel);
|
||||
|
||||
m_waitDlg->setLayout(l);
|
||||
m_waitDlg->show();
|
||||
m_waitDlg->raise();
|
||||
|
||||
|
||||
m_waitDlg->setLayout(l);
|
||||
m_waitDlg->show();
|
||||
m_waitDlg->raise();
|
||||
}
|
||||
|
||||
|
||||
void LtsProgressDialogHelper::slotStopWaitForReplyWindow(const ReplyResult &replyResult, const QString &replyString)
|
||||
void LtsProgressDialogHelper::slotStopWaitForReplyWindow(const ReplyResult& replyResult, const QString& replyString)
|
||||
{
|
||||
if (m_waitDlg == nullptr)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = nullptr;
|
||||
|
||||
|
||||
QString resultText = tr("Unknown result (%1)!").arg((int)replyResult);
|
||||
|
||||
switch (replyResult)
|
||||
{
|
||||
case ReplyResult::Close:
|
||||
if (m_waitDlg == nullptr)
|
||||
{
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
case ReplyResult::Success:
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = nullptr;
|
||||
|
||||
QString resultText = tr("Unknown result (%1)!").arg((int)replyResult);
|
||||
|
||||
switch (replyResult)
|
||||
{
|
||||
resultText = tr("Operation was successful");
|
||||
break;
|
||||
case ReplyResult::Close: {
|
||||
return;
|
||||
}
|
||||
|
||||
case ReplyResult::Success: {
|
||||
resultText = tr("Operation was successful");
|
||||
break;
|
||||
}
|
||||
|
||||
case ReplyResult::Failure: {
|
||||
resultText = tr("Operation has failed!\nReason: '%1'").arg(replyString);
|
||||
break;
|
||||
}
|
||||
|
||||
case ReplyResult::TimeOut: {
|
||||
resultText = tr("Operation has timed out and could not be processed! Please try again later");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case ReplyResult::Failure:
|
||||
{
|
||||
resultText = tr("Operation has failed!\nReason: '%1'").arg(replyString);
|
||||
break;
|
||||
}
|
||||
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
||||
|
||||
case ReplyResult::TimeOut:
|
||||
{
|
||||
resultText = tr("Operation has timed out and could not be processed! Please try again later");
|
||||
break;
|
||||
}
|
||||
}
|
||||
QVBoxLayout* newLayout = new QVBoxLayout(m_waitDlg);
|
||||
newLayout->addWidget(new QLabel(resultText, m_waitDlg));
|
||||
|
||||
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
||||
QPushButton* btn = new QPushButton(tr("OK"), m_waitDlg);
|
||||
connect(btn, &QPushButton::clicked, this, &LtsProgressDialogHelper::accept);
|
||||
|
||||
QVBoxLayout *newLayout = new QVBoxLayout(m_waitDlg);
|
||||
newLayout->addWidget(new QLabel(resultText, m_waitDlg));
|
||||
newLayout->addWidget(btn);
|
||||
|
||||
QPushButton *btn = new QPushButton(tr("OK"),m_waitDlg);
|
||||
connect(btn, &QPushButton::clicked,
|
||||
this, &LtsProgressDialogHelper::accept);
|
||||
|
||||
newLayout->addWidget(btn);
|
||||
|
||||
m_waitDlg->setLayout(newLayout);
|
||||
m_waitDlg->show();
|
||||
|
||||
|
||||
m_waitDlg->setLayout(newLayout);
|
||||
m_waitDlg->show();
|
||||
}
|
||||
|
||||
|
||||
void LtsProgressDialogHelper::accept()
|
||||
{
|
||||
m_waitDlg->accept();
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = nullptr;
|
||||
emit accepted();
|
||||
m_waitDlg->accept();
|
||||
m_waitDlg->deleteLater();
|
||||
m_waitDlg = nullptr;
|
||||
emit accepted();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+30
-34
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
@@ -15,52 +14,49 @@ namespace LtsWidgets
|
||||
{
|
||||
class LtsFramelessDialog;
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsProgressDialogHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
enum class ReplyResult {
|
||||
Close = 0,
|
||||
Success,
|
||||
Failure,
|
||||
TimeOut,
|
||||
};
|
||||
|
||||
enum class ReplyResult
|
||||
{
|
||||
Close = 0,
|
||||
Success,
|
||||
Failure,
|
||||
TimeOut,
|
||||
};
|
||||
explicit LtsProgressDialogHelper(QWidget* parent = nullptr);
|
||||
~LtsProgressDialogHelper();
|
||||
|
||||
explicit LtsProgressDialogHelper(QWidget *parent = nullptr);
|
||||
~LtsProgressDialogHelper();
|
||||
bool isShown() const { return !!m_waitDlg; }
|
||||
void setCustomText(const QString &customText = QString());
|
||||
bool isShown() const
|
||||
{
|
||||
return !!m_waitDlg;
|
||||
}
|
||||
|
||||
void setParentWidget(QWidget *newParent);
|
||||
void setCustomText(const QString& customText = QString());
|
||||
|
||||
public slots:
|
||||
|
||||
void setParentWidget(QWidget* newParent);
|
||||
|
||||
void slotShowWaitForReplyWindow();
|
||||
public slots:
|
||||
|
||||
|
||||
void slotShowWaitForReplyWindow();
|
||||
|
||||
void slotStopWaitForReplyWindow(const LtsWidgets::LtsProgressDialogHelper::ReplyResult &replyResult = ReplyResult::Close ,
|
||||
const QString &replyString = QString());
|
||||
void
|
||||
slotStopWaitForReplyWindow(const LtsWidgets::LtsProgressDialogHelper::ReplyResult& replyResult = ReplyResult::Close,
|
||||
const QString& replyString = QString());
|
||||
|
||||
private:
|
||||
QPointer<LtsFramelessDialog> m_waitDlg;
|
||||
QWidget *m_parentWidget;
|
||||
QPointer<QLabel> m_textLabel;
|
||||
private:
|
||||
QPointer<LtsFramelessDialog> m_waitDlg;
|
||||
QWidget* m_parentWidget;
|
||||
QPointer<QLabel> m_textLabel;
|
||||
|
||||
signals:
|
||||
|
||||
signals:
|
||||
|
||||
void accepted();
|
||||
void accepted();
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
private slots:
|
||||
void accept();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+479
-622
File diff suppressed because it is too large.
Load diff
Executable → Regular
+60
-155
@@ -1,14 +1,9 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QSlider>
|
||||
|
||||
namespace LtsWidgets
|
||||
@@ -16,180 +11,90 @@ namespace LtsWidgets
|
||||
|
||||
class LtsRangeSliderPrivate;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsRangeSlider : public QSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue)
|
||||
Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue)
|
||||
Q_PROPERTY(int minimumPosition READ minimumPosition WRITE setMinimumPosition)
|
||||
Q_PROPERTY(int maximumPosition READ maximumPosition WRITE setMaximumPosition)
|
||||
Q_PROPERTY(bool symmetricMoves READ symmetricMoves WRITE setSymmetricMoves)
|
||||
Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip)
|
||||
Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue)
|
||||
Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue)
|
||||
Q_PROPERTY(int minimumPosition READ minimumPosition WRITE setMinimumPosition)
|
||||
Q_PROPERTY(int maximumPosition READ maximumPosition WRITE setMaximumPosition)
|
||||
Q_PROPERTY(bool symmetricMoves READ symmetricMoves WRITE setSymmetricMoves)
|
||||
Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip)
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
explicit LtsRangeSlider(Qt::Orientation o, QWidget *parent = nullptr);
|
||||
explicit LtsRangeSlider(QWidget *parent = nullptr)
|
||||
: LtsRangeSlider(Qt::Vertical, parent)
|
||||
{}
|
||||
~LtsRangeSlider();
|
||||
public:
|
||||
explicit LtsRangeSlider(Qt::Orientation o, QWidget* parent = nullptr);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int minimumValue() const;
|
||||
explicit LtsRangeSlider(QWidget* parent = nullptr) : LtsRangeSlider(Qt::Vertical, parent) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int maximumValue() const;
|
||||
~LtsRangeSlider();
|
||||
|
||||
|
||||
|
||||
|
||||
int minimumPosition() const;
|
||||
void setMinimumPosition(int min);
|
||||
int minimumValue() const;
|
||||
|
||||
|
||||
|
||||
|
||||
int maximumPosition() const;
|
||||
void setMaximumPosition(int max);
|
||||
int maximumValue() const;
|
||||
|
||||
|
||||
|
||||
|
||||
void setPositions(int min, int max);
|
||||
int minimumPosition() const;
|
||||
void setMinimumPosition(int min);
|
||||
|
||||
|
||||
|
||||
|
||||
bool symmetricMoves() const;
|
||||
void setSymmetricMoves(bool symmetry);
|
||||
int maximumPosition() const;
|
||||
void setMaximumPosition(int max);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QString handleToolTip() const;
|
||||
void setHandleToolTip(const QString &toolTip);
|
||||
void setPositions(int min, int max);
|
||||
|
||||
|
||||
|
||||
bool isMinimumSliderDown() const;
|
||||
|
||||
|
||||
bool isMaximumSliderDown() const;
|
||||
bool symmetricMoves() const;
|
||||
void setSymmetricMoves(bool symmetry);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
|
||||
void minimumValueChanged(int min);
|
||||
|
||||
|
||||
|
||||
void maximumValueChanged(int max);
|
||||
|
||||
|
||||
void valuesChanged(int min, int max);
|
||||
QString handleToolTip() const;
|
||||
void setHandleToolTip(const QString& toolTip);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void minimumPositionChanged(int min);
|
||||
bool isMinimumSliderDown() const;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void maximumPositionChanged(int max);
|
||||
bool isMaximumSliderDown() const;
|
||||
|
||||
|
||||
|
||||
|
||||
void positionsChanged(int min, int max);
|
||||
Q_SIGNALS:
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setMinimumValue(int min);
|
||||
void minimumValueChanged(int min);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setMaximumValue(int max);
|
||||
void maximumValueChanged(int max);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setValues(int min, int max);
|
||||
void valuesChanged(int min, int max);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onRangeChanged(int minimum, int maximum);
|
||||
void minimumPositionChanged(int min);
|
||||
|
||||
protected:
|
||||
LtsRangeSlider(LtsRangeSliderPrivate *impl, Qt::Orientation o, QWidget *parent = nullptr);
|
||||
void maximumPositionChanged(int max);
|
||||
|
||||
|
||||
|
||||
void mousePressEvent(QMouseEvent *ev) override;
|
||||
void mouseMoveEvent(QMouseEvent *ev) override;
|
||||
void mouseReleaseEvent(QMouseEvent *ev) override;
|
||||
void positionsChanged(int min, int max);
|
||||
|
||||
|
||||
|
||||
void paintEvent(QPaintEvent *ev) override;
|
||||
void initMinimumSliderStyleOption(QStyleOptionSlider *option) const;
|
||||
void initMaximumSliderStyleOption(QStyleOptionSlider *option) const;
|
||||
public Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
bool event(QEvent *event) override;
|
||||
void setMinimumValue(int min);
|
||||
|
||||
protected:
|
||||
QScopedPointer<LtsRangeSliderPrivate> d_ptr;
|
||||
void setMaximumValue(int max);
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(LtsRangeSlider)
|
||||
Q_DISABLE_COPY(LtsRangeSlider)
|
||||
void setValues(int min, int max);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onRangeChanged(int minimum, int maximum);
|
||||
|
||||
protected:
|
||||
LtsRangeSlider(LtsRangeSliderPrivate* impl, Qt::Orientation o, QWidget* parent = nullptr);
|
||||
|
||||
void mousePressEvent(QMouseEvent* ev) override;
|
||||
void mouseMoveEvent(QMouseEvent* ev) override;
|
||||
void mouseReleaseEvent(QMouseEvent* ev) override;
|
||||
|
||||
void paintEvent(QPaintEvent* ev) override;
|
||||
void initMinimumSliderStyleOption(QStyleOptionSlider* option) const;
|
||||
void initMaximumSliderStyleOption(QStyleOptionSlider* option) const;
|
||||
|
||||
bool event(QEvent* event) override;
|
||||
|
||||
protected:
|
||||
QScopedPointer<LtsRangeSliderPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(LtsRangeSlider)
|
||||
Q_DISABLE_COPY(LtsRangeSlider)
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+105
-137
@@ -1,212 +1,180 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_selection_popup.h"
|
||||
#include "ui_lts_selection_popup.h"
|
||||
#include "lts_base.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "lts_base.h"
|
||||
#include "ui_lts_selection_popup.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QRadioButton>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#ifdef NEVER
|
||||
# include <QDebug>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#endif
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class RadioButton : public QRadioButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RadioButton(int row, const QString &text)
|
||||
: QRadioButton(text)
|
||||
, m_row(row)
|
||||
{}
|
||||
public:
|
||||
explicit RadioButton(int row, const QString& text) : QRadioButton(text), m_row(row) {}
|
||||
|
||||
int row() const { return m_row; }
|
||||
int row() const
|
||||
{
|
||||
return m_row;
|
||||
}
|
||||
|
||||
signals:
|
||||
void doubleClickEvent();
|
||||
signals:
|
||||
void doubleClickEvent();
|
||||
|
||||
private:
|
||||
int m_row;
|
||||
private:
|
||||
int m_row;
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent *) override
|
||||
{
|
||||
emit doubleClickEvent();
|
||||
}
|
||||
void mouseDoubleClickEvent(QMouseEvent*) override
|
||||
{
|
||||
emit doubleClickEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
LtsSelectionPopup::LtsSelectionPopup(QAbstractItemModel* model,
|
||||
int currentIndex,
|
||||
QWidget *parent)
|
||||
: LtsFramelessDialog(parent, Behaviour::Popup)
|
||||
, m_ui(new Ui::LtsSelectionPopup)
|
||||
, m_currentIndex(currentIndex)
|
||||
, m_firstIndex(currentIndex)
|
||||
, m_filter(new QSortFilterProxyModel(this))
|
||||
, m_valid(false)
|
||||
LtsSelectionPopup::LtsSelectionPopup(QAbstractItemModel* model, int currentIndex, QWidget* parent)
|
||||
: LtsFramelessDialog(parent, Behaviour::Popup), m_ui(new Ui::LtsSelectionPopup), m_currentIndex(currentIndex),
|
||||
m_firstIndex(currentIndex), m_filter(new QSortFilterProxyModel(this)), m_valid(false)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_filter->setSourceModel(model);
|
||||
m_filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_filter->setSourceModel(model);
|
||||
m_filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
slotFilterChanged();
|
||||
#ifdef TABLET_MODE
|
||||
slotFilterChanged();
|
||||
#ifdef TABLET_MODE
|
||||
m_ui->leSearch->setVisible(false);
|
||||
m_ui->label->setVisible(false);
|
||||
#endif
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, &LtsSelectionPopup::reject);
|
||||
connect(m_ui->pbSelect, &QPushButton::clicked, this, &LtsSelectionPopup::accept);
|
||||
connect(m_ui->leSearch, &QLineEdit::textEdited,
|
||||
this, &LtsSelectionPopup::slotFilterChanged);
|
||||
#endif
|
||||
connect(m_ui->pbCancel, &QPushButton::clicked, this, &LtsSelectionPopup::reject);
|
||||
connect(m_ui->pbSelect, &QPushButton::clicked, this, &LtsSelectionPopup::accept);
|
||||
connect(m_ui->leSearch, &QLineEdit::textEdited, this, &LtsSelectionPopup::slotFilterChanged);
|
||||
|
||||
#ifdef NEVER
|
||||
|
||||
#ifdef NEVER
|
||||
|
||||
connect(this, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::currentIndexChanged), this,
|
||||
[](int idx) { qCritical() << " LtsSelectionPopup: called: currentIndexChanged(int), idx=" << idx; });
|
||||
|
||||
connect(this, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::activated), this,
|
||||
[](int idx) { qCritical() << " LtsSelectionPopup: called: activated(int), idx=" << idx; });
|
||||
|
||||
|
||||
|
||||
|
||||
connect(this, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::currentIndexChanged), this, [](int idx){
|
||||
qCritical() << " LtsSelectionPopup: called: currentIndexChanged(int), idx=" << idx;
|
||||
});
|
||||
|
||||
|
||||
connect(this, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::activated), this, [](int idx){
|
||||
qCritical() << " LtsSelectionPopup: called: activated(int), idx=" << idx;
|
||||
});
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
LtsSelectionPopup::~LtsSelectionPopup()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void LtsSelectionPopup::slotFilterChanged()
|
||||
{
|
||||
m_filter->setFilterWildcard(m_ui->leSearch->text().count() ? m_ui->leSearch->text() : QStringLiteral("*") );
|
||||
refresh();
|
||||
m_filter->setFilterWildcard(m_ui->leSearch->text().count() ? m_ui->leSearch->text() : QStringLiteral("*"));
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void LtsSelectionPopup::refresh()
|
||||
{
|
||||
m_valid = false;
|
||||
qDeleteAll(m_ui->itemLayoutWidget->findChildren<RadioButton*>());
|
||||
QLayoutItem *tem = nullptr;
|
||||
if (m_ui->itemLayoutWidget->layout()->count() > 0)
|
||||
{
|
||||
tem = m_ui->itemLayoutWidget->layout()->takeAt(0);
|
||||
}
|
||||
|
||||
int count = m_filter->rowCount();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int realRow = m_filter->mapToSource(m_filter->index(i, 0)).row();
|
||||
|
||||
RadioButton *rbItem = new RadioButton(realRow, m_filter->data(m_filter->index(i, 0)).toString());
|
||||
int disable = m_filter->data(m_filter->index(i, 0), Qt::UserRole-1).toInt();
|
||||
if (disable == 1)
|
||||
rbItem->setEnabled(false);
|
||||
m_ui->itemLayoutWidget->layout()->addWidget(rbItem);
|
||||
|
||||
if (realRow == m_currentIndex)
|
||||
m_valid = false;
|
||||
qDeleteAll(m_ui->itemLayoutWidget->findChildren<RadioButton*>());
|
||||
QLayoutItem* tem = nullptr;
|
||||
if (m_ui->itemLayoutWidget->layout()->count() > 0)
|
||||
{
|
||||
rbItem->setChecked(true);
|
||||
m_valid = true;
|
||||
tem = m_ui->itemLayoutWidget->layout()->takeAt(0);
|
||||
}
|
||||
|
||||
connect(rbItem, &RadioButton::doubleClickEvent,
|
||||
this, &LtsSelectionPopup::accept);
|
||||
connect(rbItem, &RadioButton::toggled,
|
||||
this, [this](bool checked)
|
||||
int count = m_filter->rowCount();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (checked)
|
||||
m_ui->pbSelect->setEnabled(true);
|
||||
});
|
||||
}
|
||||
if (tem)
|
||||
m_ui->itemLayoutWidget->layout()->addItem(tem);
|
||||
int realRow = m_filter->mapToSource(m_filter->index(i, 0)).row();
|
||||
|
||||
if (count == 1)
|
||||
m_valid = true;
|
||||
RadioButton* rbItem = new RadioButton(realRow, m_filter->data(m_filter->index(i, 0)).toString());
|
||||
int disable = m_filter->data(m_filter->index(i, 0), Qt::UserRole - 1).toInt();
|
||||
if (disable == 1)
|
||||
rbItem->setEnabled(false);
|
||||
m_ui->itemLayoutWidget->layout()->addWidget(rbItem);
|
||||
|
||||
m_ui->pbSelect->setEnabled(m_valid);
|
||||
if (realRow == m_currentIndex)
|
||||
{
|
||||
rbItem->setChecked(true);
|
||||
m_valid = true;
|
||||
}
|
||||
|
||||
connect(rbItem, &RadioButton::doubleClickEvent, this, &LtsSelectionPopup::accept);
|
||||
connect(rbItem, &RadioButton::toggled, this, [this](bool checked) {
|
||||
if (checked)
|
||||
m_ui->pbSelect->setEnabled(true);
|
||||
});
|
||||
}
|
||||
if (tem)
|
||||
m_ui->itemLayoutWidget->layout()->addItem(tem);
|
||||
|
||||
if (count == 1)
|
||||
m_valid = true;
|
||||
|
||||
m_ui->pbSelect->setEnabled(m_valid);
|
||||
}
|
||||
|
||||
|
||||
void LtsSelectionPopup::showEvent(QShowEvent *event)
|
||||
void LtsSelectionPopup::showEvent(QShowEvent* event)
|
||||
{
|
||||
LtsFramelessDialog::showEvent(event);
|
||||
m_ui->leSearch->setFocus();
|
||||
LtsFramelessDialog::showEvent(event);
|
||||
m_ui->leSearch->setFocus();
|
||||
|
||||
resize(sizeHint().width() + m_ui->scrollArea->horizontalScrollBar()->height() , sizeHint().height());
|
||||
resize(sizeHint().width() + m_ui->scrollArea->horizontalScrollBar()->height(), sizeHint().height());
|
||||
}
|
||||
|
||||
|
||||
void LtsSelectionPopup::selectItem(int row, bool bCurrentIndexChanged, bool bActivated)
|
||||
{
|
||||
|
||||
|
||||
if (bCurrentIndexChanged)
|
||||
emit currentIndexChanged(row);
|
||||
if (bCurrentIndexChanged)
|
||||
emit currentIndexChanged(row);
|
||||
|
||||
if (bActivated)
|
||||
emit activated(row);
|
||||
if (bActivated)
|
||||
emit activated(row);
|
||||
|
||||
m_ui->pbSelect->setEnabled(true);
|
||||
m_ui->pbSelect->setEnabled(true);
|
||||
|
||||
LtsFramelessDialog::accept();
|
||||
LtsFramelessDialog::accept();
|
||||
}
|
||||
|
||||
|
||||
void LtsSelectionPopup::accept()
|
||||
{
|
||||
const QList<RadioButton *> items = m_ui->itemLayoutWidget->findChildren<RadioButton *>();
|
||||
const QList<RadioButton*> items = m_ui->itemLayoutWidget->findChildren<RadioButton*>();
|
||||
|
||||
int count = items.count();
|
||||
int count = items.count();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
const RadioButton *rb = items.at(i);
|
||||
|
||||
if (rb->isChecked())
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int realRow = m_filter->mapToSource(m_filter->index(i, 0)).row();
|
||||
const RadioButton* rb = items.at(i);
|
||||
|
||||
bool bCurrentIndexChanged = realRow != m_firstIndex;
|
||||
bool bActivated = true;
|
||||
selectItem(realRow, bCurrentIndexChanged, bActivated);
|
||||
return;
|
||||
if (rb->isChecked())
|
||||
{
|
||||
int realRow = m_filter->mapToSource(m_filter->index(i, 0)).row();
|
||||
|
||||
bool bCurrentIndexChanged = realRow != m_firstIndex;
|
||||
bool bActivated = true;
|
||||
selectItem(realRow, bCurrentIndexChanged, bActivated);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
const RadioButton *rb = items.at(0);
|
||||
selectItem(rb->row(), true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
const RadioButton* rb = items.at(0);
|
||||
selectItem(rb->row(), true, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
|
||||
#include "lts_selection_popup.moc"
|
||||
Executable → Regular
+22
-52
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_frameless_dialog.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@@ -19,66 +17,38 @@ class QSortFilterProxyModel;
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsSelectionPopup : public LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
LtsSelectionPopup(QAbstractItemModel* model, int currentIndex, QWidget* parent = nullptr);
|
||||
~LtsSelectionPopup();
|
||||
|
||||
LtsSelectionPopup(QAbstractItemModel *model,
|
||||
int currentIndex,
|
||||
QWidget *parent = nullptr);
|
||||
~LtsSelectionPopup();
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
Ui::LtsSelectionPopup* m_ui;
|
||||
int m_currentIndex;
|
||||
int m_firstIndex;
|
||||
QSortFilterProxyModel* m_filter;
|
||||
bool m_valid;
|
||||
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
Ui::LtsSelectionPopup *m_ui;
|
||||
int m_currentIndex;
|
||||
int m_firstIndex;
|
||||
QSortFilterProxyModel *m_filter;
|
||||
bool m_valid;
|
||||
void selectItem(int row, bool bCurrentIndexChanged, bool bActivated);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void refresh();
|
||||
void activated(int index);
|
||||
|
||||
|
||||
void currentIndexChanged(int index);
|
||||
|
||||
void selectItem(int row, bool bCurrentIndexChanged, bool bActivated);
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void activated(int index);
|
||||
|
||||
|
||||
|
||||
void currentIndexChanged(int index);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
void accept() override;
|
||||
|
||||
|
||||
|
||||
void slotFilterChanged();
|
||||
void accept() override;
|
||||
|
||||
void slotFilterChanged();
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+127
-139
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_spinbox.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -8,166 +7,155 @@
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsSpinBox::LtsSpinBox(QWidget *parent)
|
||||
: QSpinBox(parent)
|
||||
LtsSpinBox::LtsSpinBox(QWidget* parent) : QSpinBox(parent) {}
|
||||
|
||||
QValidator::State LtsSpinBox::validate(QString& input, int& pos) const
|
||||
{
|
||||
}
|
||||
|
||||
QValidator::State LtsSpinBox::validate(QString &input, int &pos) const
|
||||
{
|
||||
QIntValidator validator;
|
||||
for (auto range : m_validRanges)
|
||||
{
|
||||
validator.setBottom(range.first);
|
||||
validator.setTop(range.second);
|
||||
QValidator::State state = validator.validate(input, pos);
|
||||
if (state == QValidator::Invalid ||
|
||||
state == QValidator::Intermediate)
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
int value = input.toInt();
|
||||
value -= minimum();
|
||||
return (value % singleStep() == 0) ? QValidator::Acceptable : QValidator::Intermediate;
|
||||
}
|
||||
|
||||
void LtsSpinBox::fixup(QString &str) const
|
||||
{
|
||||
QSpinBox::fixup(str);
|
||||
|
||||
if (singleStep() == 1)
|
||||
return;
|
||||
|
||||
bool bOk;
|
||||
int value = str.toInt(&bOk);
|
||||
if (!bOk)
|
||||
return;
|
||||
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
value += singleStep();
|
||||
|
||||
value -= remainder;
|
||||
|
||||
if (value > maximum())
|
||||
value -= singleStep();
|
||||
|
||||
str = QString::number(value);
|
||||
}
|
||||
|
||||
bool LtsSpinBox::setExclusionRanges(const QVector<QPair<int,int> > &exclusionRanges, bool preserveCurrentValues)
|
||||
{
|
||||
bool retVal = true;
|
||||
|
||||
auto newExclusions = exclusionRanges;
|
||||
|
||||
if (preserveCurrentValues)
|
||||
newExclusions += m_exclusions;
|
||||
|
||||
for (auto &elem : newExclusions)
|
||||
{
|
||||
if (elem.first > elem.second)
|
||||
QIntValidator validator;
|
||||
for (auto range : m_validRanges)
|
||||
{
|
||||
int tmp = elem.first;
|
||||
elem.first= elem.second;
|
||||
elem.second = tmp;
|
||||
validator.setBottom(range.first);
|
||||
validator.setTop(range.second);
|
||||
QValidator::State state = validator.validate(input, pos);
|
||||
if (state == QValidator::Invalid || state == QValidator::Intermediate)
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(newExclusions.begin(), newExclusions.end(), [](const QPair<int,int> &a, const QPair<int,int> &b) { return a.first < b.first; });
|
||||
for (int i=0; i<newExclusions.size()-1; ++i)
|
||||
{
|
||||
|
||||
if (newExclusions[i].second >= newExclusions[i+1].first)
|
||||
|
||||
int value = input.toInt();
|
||||
value -= minimum();
|
||||
return (value % singleStep() == 0) ? QValidator::Acceptable : QValidator::Intermediate;
|
||||
}
|
||||
|
||||
void LtsSpinBox::fixup(QString& str) const
|
||||
{
|
||||
QSpinBox::fixup(str);
|
||||
|
||||
if (singleStep() == 1)
|
||||
return;
|
||||
|
||||
bool bOk;
|
||||
int value = str.toInt(&bOk);
|
||||
if (!bOk)
|
||||
return;
|
||||
|
||||
int remainder = (value - minimum()) % singleStep();
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
value += singleStep();
|
||||
|
||||
value -= remainder;
|
||||
|
||||
if (value > maximum())
|
||||
value -= singleStep();
|
||||
|
||||
str = QString::number(value);
|
||||
}
|
||||
|
||||
bool LtsSpinBox::setExclusionRanges(const QVector<QPair<int, int>>& exclusionRanges, bool preserveCurrentValues)
|
||||
{
|
||||
bool retVal = true;
|
||||
|
||||
auto newExclusions = exclusionRanges;
|
||||
|
||||
if (preserveCurrentValues)
|
||||
newExclusions += m_exclusions;
|
||||
|
||||
for (auto& elem : newExclusions)
|
||||
{
|
||||
retVal = false;
|
||||
break;
|
||||
if (elem.first > elem.second)
|
||||
{
|
||||
int tmp = elem.first;
|
||||
elem.first = elem.second;
|
||||
elem.second = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!retVal || newExclusions[0].first <= minimum() || newExclusions[newExclusions.size()-1].second >= maximum())
|
||||
{
|
||||
|
||||
if (!preserveCurrentValues)
|
||||
m_exclusions.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_exclusions = exclusionRanges;
|
||||
|
||||
|
||||
m_validRanges.clear();
|
||||
if (m_exclusions[0].first - 1 > minimum())
|
||||
m_validRanges.append({minimum(), m_exclusions[0].first - 1});
|
||||
for (int i=0; i<m_exclusions.size()-1; ++i)
|
||||
{
|
||||
|
||||
if (m_exclusions[i].second + 1 < m_exclusions[i+1].first - 1)
|
||||
m_validRanges.append({m_exclusions[i].second + 1, m_exclusions[i+1].first - 1});
|
||||
}
|
||||
if (m_exclusions[m_exclusions.size()-1].second + 1 < maximum())
|
||||
m_validRanges.append({m_exclusions[0].first - 1, maximum()});
|
||||
std::sort(newExclusions.begin(), newExclusions.end(),
|
||||
[](const QPair<int, int>& a, const QPair<int, int>& b) { return a.first < b.first; });
|
||||
for (int i = 0; i < newExclusions.size() - 1; ++i)
|
||||
{
|
||||
|
||||
return true;
|
||||
if (newExclusions[i].second >= newExclusions[i + 1].first)
|
||||
{
|
||||
retVal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!retVal || newExclusions[0].first <= minimum() || newExclusions[newExclusions.size() - 1].second >= maximum())
|
||||
{
|
||||
|
||||
if (!preserveCurrentValues)
|
||||
m_exclusions.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_exclusions = exclusionRanges;
|
||||
|
||||
m_validRanges.clear();
|
||||
if (m_exclusions[0].first - 1 > minimum())
|
||||
m_validRanges.append({minimum(), m_exclusions[0].first - 1});
|
||||
for (int i = 0; i < m_exclusions.size() - 1; ++i)
|
||||
{
|
||||
|
||||
if (m_exclusions[i].second + 1 < m_exclusions[i + 1].first - 1)
|
||||
m_validRanges.append({m_exclusions[i].second + 1, m_exclusions[i + 1].first - 1});
|
||||
}
|
||||
if (m_exclusions[m_exclusions.size() - 1].second + 1 < maximum())
|
||||
m_validRanges.append({m_exclusions[0].first - 1, maximum()});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LtsSpinBox::addExclusionRange(int min, int max)
|
||||
{
|
||||
return setExclusionRanges({{min, max}}, true);
|
||||
return setExclusionRanges({{min, max}}, true);
|
||||
}
|
||||
|
||||
void LtsSpinBox::clearExclusionRanges()
|
||||
{
|
||||
m_exclusions.clear();
|
||||
m_exclusions.clear();
|
||||
}
|
||||
|
||||
LtsDoubleSpinBox::LtsDoubleSpinBox(QWidget* parent) : QDoubleSpinBox(parent) {}
|
||||
|
||||
LtsDoubleSpinBox::LtsDoubleSpinBox(QWidget *parent)
|
||||
: QDoubleSpinBox(parent)
|
||||
QValidator::State LtsDoubleSpinBox::validate(QString& input, int& pos) const
|
||||
{
|
||||
QDoubleValidator validator;
|
||||
validator.setBottom(minimum());
|
||||
validator.setTop(maximum());
|
||||
QValidator::State state = validator.validate(input, pos);
|
||||
if (state == QValidator::Invalid || state == QValidator::Intermediate)
|
||||
return state;
|
||||
|
||||
double value = input.toDouble();
|
||||
value -= minimum();
|
||||
return qFuzzyCompare(std::fmod(value, singleStep()), 0.0) ? QValidator::Acceptable : QValidator::Intermediate;
|
||||
}
|
||||
|
||||
QValidator::State LtsDoubleSpinBox::validate(QString &input, int &pos) const
|
||||
void LtsDoubleSpinBox::fixup(QString& str) const
|
||||
{
|
||||
QDoubleValidator validator;
|
||||
validator.setBottom(minimum());
|
||||
validator.setTop(maximum());
|
||||
QValidator::State state = validator.validate(input, pos);
|
||||
if (state == QValidator::Invalid ||
|
||||
state == QValidator::Intermediate)
|
||||
return state;
|
||||
QDoubleSpinBox::fixup(str);
|
||||
|
||||
|
||||
double value = input.toDouble();
|
||||
value -= minimum();
|
||||
return qFuzzyCompare(std::fmod(value, singleStep()), 0.0) ? QValidator::Acceptable : QValidator::Intermediate;
|
||||
if (qFuzzyCompare(singleStep(), pow(10, decimals())))
|
||||
return;
|
||||
|
||||
bool bOk;
|
||||
double value = str.toDouble(&bOk);
|
||||
if (!bOk)
|
||||
return;
|
||||
|
||||
double remainder = std::fmod(value - minimum(), singleStep());
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
value += singleStep();
|
||||
|
||||
value -= remainder;
|
||||
|
||||
if (value > maximum())
|
||||
value -= singleStep();
|
||||
|
||||
str = QString::number(value, 'f', decimals());
|
||||
}
|
||||
|
||||
void LtsDoubleSpinBox::fixup(QString &str) const
|
||||
{
|
||||
QDoubleSpinBox::fixup(str);
|
||||
|
||||
if (qFuzzyCompare(singleStep(), pow(10, decimals())))
|
||||
return;
|
||||
|
||||
bool bOk;
|
||||
double value = str.toDouble(&bOk);
|
||||
if (!bOk)
|
||||
return;
|
||||
|
||||
double remainder = std::fmod(value - minimum(), singleStep());
|
||||
|
||||
if (2 * remainder > singleStep())
|
||||
value += singleStep();
|
||||
|
||||
value -= remainder;
|
||||
|
||||
if (value > maximum())
|
||||
value -= singleStep();
|
||||
|
||||
str = QString::number(value, 'f', decimals());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+43
-32
@@ -1,11 +1,9 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSpinBox>
|
||||
|
||||
namespace LtsWidgets
|
||||
@@ -13,49 +11,62 @@ namespace LtsWidgets
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsSpinBox(QWidget *parent = nullptr);
|
||||
~LtsSpinBox() = default;
|
||||
public:
|
||||
explicit LtsSpinBox(QWidget* parent = nullptr);
|
||||
~LtsSpinBox() = default;
|
||||
|
||||
public slots:
|
||||
void setValue(int val) { QString valStr = QString::number(val); fixup(valStr); QSpinBox::setValue(valStr.toInt()); }
|
||||
bool setExclusionRanges(const QVector<QPair<int,int> > &exclusionRanges, bool preserveCurrentValues = false);
|
||||
bool addExclusionRange(int min, int max);
|
||||
void clearExclusionRanges();
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
QValidator::State validate(QString &input, int &pos) const override;
|
||||
void fixup(QString &str) const override;
|
||||
void setValue(int val)
|
||||
{
|
||||
QString valStr = QString::number(val);
|
||||
fixup(valStr);
|
||||
QSpinBox::setValue(valStr.toInt());
|
||||
}
|
||||
|
||||
private:
|
||||
bool setExclusionRanges(const QVector<QPair<int, int>>& exclusionRanges, bool preserveCurrentValues = false);
|
||||
bool addExclusionRange(int min, int max);
|
||||
void clearExclusionRanges();
|
||||
|
||||
struct
|
||||
{
|
||||
bool operator()(const QPair<int,int> &a, const QPair<int,int> &b) const { return a.first < b.first; }
|
||||
} customless;
|
||||
protected:
|
||||
QValidator::State validate(QString& input, int& pos) const override;
|
||||
void fixup(QString& str) const override;
|
||||
|
||||
QVector<QPair<int,int> > m_exclusions;
|
||||
QVector<QPair<int,int> > m_validRanges;
|
||||
private:
|
||||
struct
|
||||
{
|
||||
bool operator()(const QPair<int, int>& a, const QPair<int, int>& b) const
|
||||
{
|
||||
return a.first < b.first;
|
||||
}
|
||||
} customless;
|
||||
|
||||
QVector<QPair<int, int>> m_exclusions;
|
||||
QVector<QPair<int, int>> m_validRanges;
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsDoubleSpinBox : public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsDoubleSpinBox(QWidget *parent = nullptr);
|
||||
~LtsDoubleSpinBox() = default;
|
||||
public:
|
||||
explicit LtsDoubleSpinBox(QWidget* parent = nullptr);
|
||||
~LtsDoubleSpinBox() = default;
|
||||
|
||||
public slots:
|
||||
void setValue(double val) { QString valStr = QString::number(val); fixup(valStr); QDoubleSpinBox::setValue(valStr.toDouble()); }
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
QValidator::State validate(QString &input, int &pos) const override;
|
||||
void fixup(QString &str) const override;
|
||||
void setValue(double val)
|
||||
{
|
||||
QString valStr = QString::number(val);
|
||||
fixup(valStr);
|
||||
QDoubleSpinBox::setValue(valStr.toDouble());
|
||||
}
|
||||
|
||||
protected:
|
||||
QValidator::State validate(QString& input, int& pos) const override;
|
||||
void fixup(QString& str) const override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+39
-49
@@ -1,81 +1,71 @@
|
||||
#include "lts_splash.h"
|
||||
|
||||
#include <LtsWidgets/lts_global_wait_dialog.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFile>
|
||||
#include <QEvent>
|
||||
|
||||
#include <QFile>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
Splash::Splash()
|
||||
: QSplashScreen()
|
||||
, m_done(false)
|
||||
Splash::Splash() : QSplashScreen(), m_done(false)
|
||||
{
|
||||
static const auto splashFiles =
|
||||
{
|
||||
QStringLiteral(":/project/splash.png"),
|
||||
QStringLiteral(":/project/splash.jpg"),
|
||||
};
|
||||
for (const QString &f : splashFiles)
|
||||
{
|
||||
if (!QFile::exists(f))
|
||||
continue;
|
||||
setPixmap(QPixmap(f));
|
||||
break;
|
||||
}
|
||||
static const auto splashFiles = {
|
||||
QStringLiteral(":/project/splash.png"),
|
||||
QStringLiteral(":/project/splash.jpg"),
|
||||
};
|
||||
for (const QString& f : splashFiles)
|
||||
{
|
||||
if (!QFile::exists(f))
|
||||
continue;
|
||||
setPixmap(QPixmap(f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Splash::event(QEvent *e)
|
||||
bool Splash::event(QEvent* e)
|
||||
{
|
||||
if (e->type() == QEvent::MouseButtonPress ||
|
||||
e->type() == QEvent::MouseButtonRelease ||
|
||||
e->type() == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
e->ignore();
|
||||
return false;
|
||||
}
|
||||
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease ||
|
||||
e->type() == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
e->ignore();
|
||||
return false;
|
||||
}
|
||||
|
||||
return QSplashScreen::event(e);
|
||||
return QSplashScreen::event(e);
|
||||
}
|
||||
|
||||
|
||||
void Splash::setMessage(const QString &message)
|
||||
void Splash::setMessage(const QString& message)
|
||||
{
|
||||
showMessage(message, Qt::AlignRight | Qt::AlignBottom);
|
||||
showMessage(message, Qt::AlignRight | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
|
||||
void Splash::done()
|
||||
{
|
||||
if (m_done)
|
||||
return;
|
||||
m_done = true;
|
||||
if (m_done)
|
||||
return;
|
||||
m_done = true;
|
||||
|
||||
hide();
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
||||
hide();
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
||||
}
|
||||
|
||||
static Splash* s_splashInstance = nullptr;
|
||||
|
||||
static Splash *s_splashInstance = nullptr;
|
||||
void Splash::cleanupSplashInstance()
|
||||
{
|
||||
delete s_splashInstance;
|
||||
s_splashInstance = nullptr;
|
||||
delete s_splashInstance;
|
||||
s_splashInstance = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Splash *Splash::getInstance()
|
||||
Splash* Splash::getInstance()
|
||||
{
|
||||
if (!s_splashInstance)
|
||||
{
|
||||
s_splashInstance = new Splash;
|
||||
qAddPostRoutine(&Splash::cleanupSplashInstance);
|
||||
}
|
||||
return s_splashInstance;
|
||||
if (!s_splashInstance)
|
||||
{
|
||||
s_splashInstance = new Splash;
|
||||
qAddPostRoutine(&Splash::cleanupSplashInstance);
|
||||
}
|
||||
return s_splashInstance;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+12
-13
@@ -2,27 +2,26 @@
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QSplashScreen>
|
||||
#include <QObject>
|
||||
|
||||
#include <QSplashScreen>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT Splash : public QSplashScreen
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Splash* getInstance();
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Splash* getInstance();
|
||||
|
||||
void done();
|
||||
void setMessage(const QString &message);
|
||||
void done();
|
||||
void setMessage(const QString& message);
|
||||
|
||||
private:
|
||||
Splash();
|
||||
static void cleanupSplashInstance();
|
||||
private:
|
||||
Splash();
|
||||
static void cleanupSplashInstance();
|
||||
|
||||
bool event(QEvent *e) override;
|
||||
bool event(QEvent* e) override;
|
||||
|
||||
bool m_done;
|
||||
bool m_done;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+22
-26
@@ -1,57 +1,53 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_splitter.h"
|
||||
#include "lts_splitter_handle.h"
|
||||
|
||||
#include "lts_splitter_handle.h"
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsSplitter::LtsSplitter(QWidget *parent)
|
||||
: QSplitter(parent)
|
||||
LtsSplitter::LtsSplitter(QWidget* parent) : QSplitter(parent)
|
||||
{
|
||||
connect(this, &LtsSplitter::sizesChanged, this, &LtsSplitter::changeSizes);
|
||||
connect(this, &LtsSplitter::sizesChanged, this, &LtsSplitter::changeSizes);
|
||||
}
|
||||
|
||||
LtsSplitter::~LtsSplitter()
|
||||
{
|
||||
}
|
||||
LtsSplitter::~LtsSplitter() {}
|
||||
|
||||
QSplitterHandle *LtsSplitter::createHandle()
|
||||
QSplitterHandle* LtsSplitter::createHandle()
|
||||
{
|
||||
LtsSplitterHandle *hand = new LtsSplitterHandle(orientation(), this);
|
||||
LtsSplitterHandle* hand = new LtsSplitterHandle(orientation(), this);
|
||||
#ifdef TABLET_MODE
|
||||
setHandleWidth(25);
|
||||
setHandleWidth(25);
|
||||
#else
|
||||
setHandleWidth(10);
|
||||
setHandleWidth(10);
|
||||
#endif
|
||||
return hand;
|
||||
return hand;
|
||||
}
|
||||
|
||||
void LtsSplitter::collapseChild(const int index)
|
||||
{
|
||||
if (children().size() > index)
|
||||
{
|
||||
QWidget *widget = static_cast<QWidget*>(children().at(index));
|
||||
if (widget)
|
||||
if (children().size() > index)
|
||||
{
|
||||
QList<int> s = sizes();
|
||||
s[index] = 0;
|
||||
setSizes(s);
|
||||
QWidget* widget = static_cast<QWidget*>(children().at(index));
|
||||
if (widget)
|
||||
{
|
||||
QList<int> s = sizes();
|
||||
s[index] = 0;
|
||||
setSizes(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LtsSplitter::animate(int handleId)
|
||||
{
|
||||
LtsSplitterHandle *handle = dynamic_cast<LtsSplitterHandle*>(this->handle(handleId));
|
||||
handle->animate();
|
||||
LtsSplitterHandle* handle = dynamic_cast<LtsSplitterHandle*>(this->handle(handleId));
|
||||
handle->animate();
|
||||
}
|
||||
|
||||
void LtsSplitter::changeSizes(const QList<int> &list)
|
||||
void LtsSplitter::changeSizes(const QList<int>& list)
|
||||
{
|
||||
QSplitter::setSizes(list);
|
||||
QSplitter::setSizes(list);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+21
-19
@@ -1,38 +1,40 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QList>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSplitter>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsSplitter : public QSplitter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QList<int> sizes READ getSizes WRITE setSizes NOTIFY sizesChanged)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QList<int> sizes READ getSizes WRITE setSizes NOTIFY sizesChanged)
|
||||
|
||||
public:
|
||||
explicit LtsSplitter(QWidget *parent = nullptr);
|
||||
~LtsSplitter();
|
||||
public:
|
||||
explicit LtsSplitter(QWidget* parent = nullptr);
|
||||
~LtsSplitter();
|
||||
|
||||
QSplitterHandle *createHandle();
|
||||
void collapseChild(const int index);
|
||||
QList<int> getSizes() const { return sizes(); }
|
||||
void animate(int handleId);
|
||||
QSplitterHandle* createHandle();
|
||||
void collapseChild(const int index);
|
||||
|
||||
signals:
|
||||
void sizesChanged(const QList<int> &newSizes);
|
||||
QList<int> getSizes() const
|
||||
{
|
||||
return sizes();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void changeSizes(const QList<int> &list);
|
||||
void animate(int handleId);
|
||||
|
||||
signals:
|
||||
void sizesChanged(const QList<int>& newSizes);
|
||||
|
||||
public slots:
|
||||
void changeSizes(const QList<int>& list);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+52
-56
@@ -1,87 +1,83 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_splitter_handle.h"
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include <QBrush>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QLinearGradient>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsSplitterHandle::LtsSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
|
||||
: QSplitterHandle(orientation, parent)
|
||||
LtsSplitterHandle::LtsSplitterHandle(Qt::Orientation orientation, QSplitter* parent)
|
||||
: QSplitterHandle(orientation, parent)
|
||||
{
|
||||
auto bgrole = backgroundRole();
|
||||
QPalette p = palette();
|
||||
m_endColor = p.color(bgrole);
|
||||
|
||||
m_colorAnimation = new QPropertyAnimation(this, "splittercolor");
|
||||
m_colorAnimation->setDuration(1000);
|
||||
m_colorAnimation->setStartValue(m_currentColor);
|
||||
m_colorAnimation->setEndValue(m_endColor);
|
||||
m_colorAnimation->setLoopCount(2);
|
||||
connect(m_colorAnimation, &QPropertyAnimation::finished, this, [this]{
|
||||
m_animate = false;
|
||||
m_currentColor = m_endColor;
|
||||
repaint();
|
||||
});
|
||||
auto bgrole = backgroundRole();
|
||||
QPalette p = palette();
|
||||
m_endColor = p.color(bgrole);
|
||||
|
||||
m_colorAnimation = new QPropertyAnimation(this, "splittercolor");
|
||||
m_colorAnimation->setDuration(1000);
|
||||
m_colorAnimation->setStartValue(m_currentColor);
|
||||
m_colorAnimation->setEndValue(m_endColor);
|
||||
m_colorAnimation->setLoopCount(2);
|
||||
connect(m_colorAnimation, &QPropertyAnimation::finished, this, [this] {
|
||||
m_animate = false;
|
||||
m_currentColor = m_endColor;
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
|
||||
LtsSplitterHandle::~LtsSplitterHandle()
|
||||
{
|
||||
}
|
||||
LtsSplitterHandle::~LtsSplitterHandle() {}
|
||||
|
||||
void LtsSplitterHandle::paintEvent(QPaintEvent *event)
|
||||
void LtsSplitterHandle::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
if(!m_animate)
|
||||
{
|
||||
QSplitterHandle::paintEvent(event);
|
||||
return;
|
||||
}
|
||||
QPainter painter(this);
|
||||
QLinearGradient gradient;
|
||||
gradient.setColorAt(0, m_currentColor);
|
||||
|
||||
if (!m_animate)
|
||||
{
|
||||
QSplitterHandle::paintEvent(event);
|
||||
return;
|
||||
}
|
||||
QPainter painter(this);
|
||||
QLinearGradient gradient;
|
||||
gradient.setColorAt(0, m_currentColor);
|
||||
|
||||
if(orientation() == Qt::Horizontal)
|
||||
{
|
||||
gradient.setStart(rect().left(), rect().height()/2);
|
||||
gradient.setFinalStop(rect().height(), rect().height()/2);
|
||||
}else
|
||||
{
|
||||
gradient.setStart(rect().width()/2, rect().top());
|
||||
gradient.setFinalStop(rect().width()/2, rect().bottom()/2);
|
||||
}
|
||||
painter.fillRect(event->rect(), QBrush(gradient));
|
||||
if (orientation() == Qt::Horizontal)
|
||||
{
|
||||
gradient.setStart(rect().left(), rect().height() / 2);
|
||||
gradient.setFinalStop(rect().height(), rect().height() / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
gradient.setStart(rect().width() / 2, rect().top());
|
||||
gradient.setFinalStop(rect().width() / 2, rect().bottom() / 2);
|
||||
}
|
||||
painter.fillRect(event->rect(), QBrush(gradient));
|
||||
}
|
||||
|
||||
void LtsSplitterHandle::animate()
|
||||
{
|
||||
if (m_colorAnimation->state() == QPropertyAnimation::Running)
|
||||
return;
|
||||
if (m_colorAnimation->state() == QPropertyAnimation::Running)
|
||||
return;
|
||||
|
||||
m_currentColor = QColor(239,87,50);
|
||||
m_animate = true;
|
||||
m_colorAnimation->start();
|
||||
m_currentColor = QColor(239, 87, 50);
|
||||
m_animate = true;
|
||||
m_colorAnimation->start();
|
||||
}
|
||||
|
||||
QColor LtsSplitterHandle::splitterColor() const
|
||||
{
|
||||
return m_currentColor;
|
||||
return m_currentColor;
|
||||
}
|
||||
|
||||
void LtsSplitterHandle::setCurrentColor(const QColor ¤tcolor)
|
||||
void LtsSplitterHandle::setCurrentColor(const QColor& currentcolor)
|
||||
{
|
||||
if (currentcolor == m_currentColor)
|
||||
return;
|
||||
m_currentColor = currentcolor;
|
||||
repaint();
|
||||
if (currentcolor == m_currentColor)
|
||||
return;
|
||||
m_currentColor = currentcolor;
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+17
-20
@@ -1,40 +1,37 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QSplitterHandle>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSplitterHandle>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsSplitterHandle : public QSplitterHandle
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor splittercolor READ splitterColor WRITE setCurrentColor DESIGNABLE false)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor splittercolor READ splitterColor WRITE setCurrentColor DESIGNABLE false)
|
||||
|
||||
public:
|
||||
explicit LtsSplitterHandle(Qt::Orientation orientation, QSplitter *parent = nullptr);
|
||||
~LtsSplitterHandle();
|
||||
public:
|
||||
explicit LtsSplitterHandle(Qt::Orientation orientation, QSplitter* parent = nullptr);
|
||||
~LtsSplitterHandle();
|
||||
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void animate();
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void animate();
|
||||
|
||||
QColor splitterColor() const;
|
||||
void setCurrentColor(const QColor ¤tcolor);
|
||||
|
||||
private:
|
||||
bool m_animate {false};
|
||||
QColor m_endColor {Qt::black};
|
||||
QColor m_currentColor{QColor(239,87,50)};
|
||||
QPropertyAnimation *m_colorAnimation;
|
||||
QColor splitterColor() const;
|
||||
void setCurrentColor(const QColor& currentcolor);
|
||||
|
||||
private:
|
||||
bool m_animate{false};
|
||||
QColor m_endColor{Qt::black};
|
||||
QColor m_currentColor{QColor(239, 87, 50)};
|
||||
QPropertyAnimation* m_colorAnimation;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+72
-78
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_tab_bar.h"
|
||||
|
||||
#include "lts_dialog.h"
|
||||
@@ -8,113 +7,108 @@
|
||||
#include "lts_events.h"
|
||||
#include "lts_tab_widget.h"
|
||||
|
||||
#include <TabBarTabStyle/tab_bar_tab_style.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QMenu>
|
||||
#include <TabBarTabStyle/tab_bar_tab_style.h>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsTabBar::LtsTabBar(bool isSecondary, QWidget *parent)
|
||||
: QTabBar(parent)
|
||||
, m_secondary(isSecondary)
|
||||
LtsTabBar::LtsTabBar(bool isSecondary, QWidget* parent) : QTabBar(parent), m_secondary(isSecondary)
|
||||
{
|
||||
setDocumentMode(true);
|
||||
setTabsClosable(true);
|
||||
setDocumentMode(true);
|
||||
setTabsClosable(true);
|
||||
|
||||
connect(this, &LtsTabBar::currentChanged, this, &LtsTabBar::updateCloseButtonColors);
|
||||
connect(this, &LtsTabBar::currentChanged, this, &LtsTabBar::updateCloseButtonColors);
|
||||
|
||||
if (m_secondary)
|
||||
{
|
||||
connect(this, &LtsTabBar::customContextMenuRequested,
|
||||
this, &LtsTabBar::onCustomContextMenuRequested);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
if (m_secondary)
|
||||
{
|
||||
connect(this, &LtsTabBar::customContextMenuRequested, this, &LtsTabBar::onCustomContextMenuRequested);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LtsTabBar::_internal_closeTab()
|
||||
void LtsTabBar::_internal_closeTab()
|
||||
{
|
||||
QObject *object = sender();
|
||||
int tabToClose = -1;
|
||||
QObject* object = sender();
|
||||
int tabToClose = -1;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
if (tabButton(i, QTabBar::RightSide) == object)
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
tabToClose = i;
|
||||
break;
|
||||
if (tabButton(i, QTabBar::RightSide) == object)
|
||||
{
|
||||
tabToClose = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tabToClose != -1)
|
||||
emit tabCloseRequested(tabToClose);
|
||||
if (tabToClose != -1)
|
||||
emit tabCloseRequested(tabToClose);
|
||||
}
|
||||
|
||||
|
||||
void LtsTabBar::updateCloseButtonColors(int newIndex)
|
||||
void LtsTabBar::updateCloseButtonColors(int newIndex)
|
||||
{
|
||||
|
||||
if (newIndex == -1)
|
||||
newIndex = currentIndex();
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
QWidget *w = tabButton(i, QTabBar::RightSide);
|
||||
CloseButton *cb = qobject_cast<CloseButton *>(w);
|
||||
if (newIndex == -1)
|
||||
newIndex = currentIndex();
|
||||
|
||||
if (!cb)
|
||||
continue;
|
||||
|
||||
QColor text;
|
||||
|
||||
bool enabled = isTabEnabled(i);
|
||||
bool selected = (i == newIndex);
|
||||
bool secondary = m_secondary;
|
||||
|
||||
if (enabled)
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
if (selected)
|
||||
text = (secondary) ? Styles::TabBarTabStyle::secondarySelected : Styles::TabBarTabStyle::primarySelected;
|
||||
else
|
||||
text = (secondary) ? Styles::TabBarTabStyle::secondaryNormal : Styles::TabBarTabStyle::primaryNormal;
|
||||
}
|
||||
else
|
||||
text = (secondary) ? Styles::TabBarTabStyle::secondaryDisabled : Styles::TabBarTabStyle::primaryDisabled;
|
||||
QWidget* w = tabButton(i, QTabBar::RightSide);
|
||||
CloseButton* cb = qobject_cast<CloseButton*>(w);
|
||||
|
||||
|
||||
cb->setFontColor(text);
|
||||
}
|
||||
if (!cb)
|
||||
continue;
|
||||
|
||||
QColor text;
|
||||
|
||||
bool enabled = isTabEnabled(i);
|
||||
bool selected = (i == newIndex);
|
||||
bool secondary = m_secondary;
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
if (selected)
|
||||
text =
|
||||
(secondary) ? Styles::TabBarTabStyle::secondarySelected : Styles::TabBarTabStyle::primarySelected;
|
||||
else
|
||||
text = (secondary) ? Styles::TabBarTabStyle::secondaryNormal : Styles::TabBarTabStyle::primaryNormal;
|
||||
}
|
||||
else
|
||||
text = (secondary) ? Styles::TabBarTabStyle::secondaryDisabled : Styles::TabBarTabStyle::primaryDisabled;
|
||||
|
||||
cb->setFontColor(text);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsTabBar::onCustomContextMenuRequested(const QPoint pos)
|
||||
{
|
||||
if (!m_secondary)
|
||||
return;
|
||||
QMenu m;
|
||||
QAction *a = new QAction(tr("Save as image"));
|
||||
connect(a, &QAction::triggered, this, [this, pos]() { LtsTabBar::onSaveCurrentWidgetAsImage(pos); });
|
||||
m.addAction(a);
|
||||
m.exec(mapToGlobal(pos));
|
||||
if (!m_secondary)
|
||||
return;
|
||||
QMenu m;
|
||||
QAction* a = new QAction(tr("Save as image"));
|
||||
connect(a, &QAction::triggered, this, [this, pos]() { LtsTabBar::onSaveCurrentWidgetAsImage(pos); });
|
||||
m.addAction(a);
|
||||
m.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void LtsTabBar::onSaveCurrentWidgetAsImage(const QPoint pos)
|
||||
{
|
||||
int curTab = tabAt(pos);
|
||||
if (curTab < 0)
|
||||
curTab = currentIndex();
|
||||
if (curTab < 0)
|
||||
return;
|
||||
LtsTabWidget *tw = qobject_cast<LtsTabWidget*>(parentWidget());
|
||||
QWidget *w = tw ? tw->widget(curTab) : nullptr;
|
||||
if (!w)
|
||||
return;
|
||||
LtsDialogHelper *helper = qobject_cast<LtsDialogHelper*>(w);
|
||||
if (helper)
|
||||
w = helper->getDialog();
|
||||
SaveImageEvent *ev = new SaveImageEvent(w, w->grab());
|
||||
ev->setAccepted(false);
|
||||
QCoreApplication::postEvent(qApp, ev);
|
||||
int curTab = tabAt(pos);
|
||||
if (curTab < 0)
|
||||
curTab = currentIndex();
|
||||
if (curTab < 0)
|
||||
return;
|
||||
LtsTabWidget* tw = qobject_cast<LtsTabWidget*>(parentWidget());
|
||||
QWidget* w = tw ? tw->widget(curTab) : nullptr;
|
||||
if (!w)
|
||||
return;
|
||||
LtsDialogHelper* helper = qobject_cast<LtsDialogHelper*>(w);
|
||||
if (helper)
|
||||
w = helper->getDialog();
|
||||
SaveImageEvent* ev = new SaveImageEvent(w, w->grab());
|
||||
ev->setAccepted(false);
|
||||
QCoreApplication::postEvent(qApp, ev);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+16
-23
@@ -1,40 +1,33 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QTabBar>
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QTabBar>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTabBar : public QTabBar
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool secondary MEMBER m_secondary)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool secondary MEMBER m_secondary)
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
explicit LtsTabBar(bool isSecondary = false, QWidget* parent = nullptr);
|
||||
|
||||
explicit LtsTabBar(bool isSecondary = false, QWidget *parent = nullptr);
|
||||
void _internal_closeTab();
|
||||
|
||||
|
||||
protected:
|
||||
void onCustomContextMenuRequested(const QPoint pos);
|
||||
void onSaveCurrentWidgetAsImage(const QPoint pos);
|
||||
|
||||
void _internal_closeTab();
|
||||
|
||||
protected:
|
||||
void onCustomContextMenuRequested(const QPoint pos);
|
||||
void onSaveCurrentWidgetAsImage(const QPoint pos);
|
||||
private:
|
||||
bool m_secondary;
|
||||
|
||||
public slots:
|
||||
void updateCloseButtonColors(int newIndex = -1);
|
||||
private:
|
||||
bool m_secondary;
|
||||
|
||||
public slots:
|
||||
void updateCloseButtonColors(int newIndex = -1);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+23
-23
@@ -2,58 +2,58 @@
|
||||
|
||||
#include "lts_tab_sequence_widget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsTabSequenceWidget::LtsTabSequenceWidget(QWidget *parent)
|
||||
: LtsAbstractSequenceWidget(parent)
|
||||
, m_twSequences(new QTabWidget(this))
|
||||
LtsTabSequenceWidget::LtsTabSequenceWidget(QWidget* parent)
|
||||
: LtsAbstractSequenceWidget(parent), m_twSequences(new QTabWidget(this))
|
||||
|
||||
{
|
||||
QHBoxLayout *gridLayout = new QHBoxLayout(this);
|
||||
gridLayout->addWidget(m_twSequences);
|
||||
gridLayout->addWidget(pbAddMember(), Qt::AlignTop);
|
||||
QHBoxLayout* gridLayout = new QHBoxLayout(this);
|
||||
gridLayout->addWidget(m_twSequences);
|
||||
gridLayout->addWidget(pbAddMember(), Qt::AlignTop);
|
||||
|
||||
m_twSequences->setCornerWidget(pbAddMember());
|
||||
pbAddMember()->setFixedSize(m_twSequences->tabBar()->size());
|
||||
pbAddMember()->setIconSize(m_twSequences->tabBar()->size());
|
||||
m_twSequences->setCornerWidget(pbAddMember());
|
||||
pbAddMember()->setFixedSize(m_twSequences->tabBar()->size());
|
||||
pbAddMember()->setIconSize(m_twSequences->tabBar()->size());
|
||||
}
|
||||
|
||||
LtsTabSequenceWidget::~LtsTabSequenceWidget()
|
||||
{
|
||||
delete pbAddMember();
|
||||
delete m_twSequences;
|
||||
delete pbAddMember();
|
||||
delete m_twSequences;
|
||||
}
|
||||
|
||||
void LtsTabSequenceWidget::setupMemberWidget(QWidget *child, QToolButton *pbChild, const QString &objectName, bool isButtonVisible)
|
||||
void LtsTabSequenceWidget::setupMemberWidget(QWidget* child, QToolButton* pbChild, const QString& objectName,
|
||||
bool isButtonVisible)
|
||||
{
|
||||
int index = m_twSequences->addTab(child, objectName);
|
||||
if(isButtonVisible)
|
||||
m_twSequences->tabBar()->setTabButton(index, QTabBar::RightSide, pbChild);
|
||||
int index = m_twSequences->addTab(child, objectName);
|
||||
if (isButtonVisible)
|
||||
m_twSequences->tabBar()->setTabButton(index, QTabBar::RightSide, pbChild);
|
||||
}
|
||||
|
||||
QWidget* LtsTabSequenceWidget::getWidget(int index)
|
||||
{
|
||||
return m_twSequences->widget(index);
|
||||
return m_twSequences->widget(index);
|
||||
}
|
||||
|
||||
QWidget* LtsTabSequenceWidget::getCurrentWidget()
|
||||
{
|
||||
return m_twSequences->currentWidget();
|
||||
return m_twSequences->currentWidget();
|
||||
}
|
||||
|
||||
int LtsTabSequenceWidget::getCurrentTabIndex()
|
||||
{
|
||||
return m_twSequences->currentIndex();
|
||||
return m_twSequences->currentIndex();
|
||||
}
|
||||
void LtsTabSequenceWidget::changeTabName(const QString &name)
|
||||
|
||||
void LtsTabSequenceWidget::changeTabName(const QString& name)
|
||||
{
|
||||
m_twSequences->setTabText(m_twSequences->currentIndex(), name);
|
||||
m_twSequences->setTabText(m_twSequences->currentIndex(), name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+12
-11
@@ -4,35 +4,36 @@
|
||||
#define LTS_TAB_SEQUENCE_WIDGET_H
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_abstract_sequence_widget.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTabWidget;
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTabSequenceWidget : public LtsAbstractSequenceWidget
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsTabSequenceWidget : public LtsAbstractSequenceWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LtsTabSequenceWidget(QWidget *parent = nullptr);
|
||||
LtsTabSequenceWidget(QWidget* parent = nullptr);
|
||||
|
||||
virtual ~LtsTabSequenceWidget();
|
||||
QWidget* getWidget(int index);
|
||||
QWidget* getCurrentWidget();
|
||||
int getCurrentTabIndex();
|
||||
void changeTabName(const QString &name);
|
||||
void changeTabName(const QString& name);
|
||||
|
||||
protected:
|
||||
void setupMemberWidget(QWidget *child, QToolButton *pbChild, const QString &objectName, bool isButtonVisible = true) override;
|
||||
void setupMemberWidget(QWidget* child, QToolButton* pbChild, const QString& objectName,
|
||||
bool isButtonVisible = true) override;
|
||||
|
||||
private:
|
||||
QTabWidget *m_twSequences = nullptr;
|
||||
};
|
||||
}
|
||||
QTabWidget* m_twSequences = nullptr;
|
||||
};
|
||||
} // namespace LtsWidgets
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+60
-111
@@ -1,164 +1,113 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QMap>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QTabWidget>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsDialogHelper;
|
||||
class LtsTabBar;
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTabWidget : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsTabWidget(QWidget* parent = nullptr, bool isSecondary = false);
|
||||
~LtsTabWidget();
|
||||
|
||||
explicit LtsTabWidget(QWidget *parent = nullptr, bool isSecondary = false);
|
||||
~LtsTabWidget();
|
||||
void setActuatorTabStyle(bool enable);
|
||||
|
||||
|
||||
void clearAll();
|
||||
|
||||
void setActuatorTabStyle(bool enable);
|
||||
void aboutToClose();
|
||||
|
||||
|
||||
LtsTabBar* tabBar();
|
||||
|
||||
void clearAll();
|
||||
void setTabBar(LtsTabBar* tabbar);
|
||||
|
||||
bool focusTab(const QString& menuGroup, const QString& identifier);
|
||||
|
||||
void aboutToClose();
|
||||
void setSubTabsVisible(bool visible);
|
||||
|
||||
|
||||
QWidget* getWidget(const QString& menuGroup, const QString& identifier);
|
||||
|
||||
LtsTabBar *tabBar();
|
||||
static bool hasUnsavedChanges(LtsTabWidget* tabWidget);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void setTabBar(LtsTabBar *tabbar);
|
||||
void signalCheckTabBarVisibility();
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
bool focusTab(const QString &menuGroup, const QString &identifier);
|
||||
void addTab(const QString& menuGroup, const QString& identifier, QWidget* widget, bool setClosable = true,
|
||||
bool focusNewTab = true);
|
||||
|
||||
|
||||
bool removeWidget(QWidget* widget);
|
||||
|
||||
void setSubTabsVisible(bool visible);
|
||||
private slots:
|
||||
|
||||
|
||||
void onRemoveTab(QObject* object);
|
||||
|
||||
QWidget *getWidget(const QString &menuGroup, const QString &identifier);
|
||||
void onCheckTabBarVisibility();
|
||||
|
||||
|
||||
void slotTabCloseRequested(int index);
|
||||
|
||||
static bool hasUnsavedChanges(LtsTabWidget *tabWidget);
|
||||
void slotCurrentChanged(int newIdx);
|
||||
|
||||
void slotMaximizeButtonClicked();
|
||||
|
||||
private:
|
||||
void addWidget(const QString& fullName, QWidget* widget, bool setClosable, bool focusNewTab = true);
|
||||
|
||||
signals:
|
||||
|
||||
QWidget* getWidget(const QString& fullName);
|
||||
|
||||
void signalCheckTabBarVisibility();
|
||||
bool focusWidget(const QString& fullName);
|
||||
|
||||
void slotWindowTitleChanged(const QString& title);
|
||||
|
||||
public slots:
|
||||
|
||||
void closeRequestTabWidget(LtsTabWidget* tabWidget);
|
||||
|
||||
void addTab(const QString &menuGroup, const QString &identifier, QWidget *widget,
|
||||
bool setClosable = true, bool focusNewTab = true);
|
||||
QPoint startPos;
|
||||
LtsTabBar* m_tabbar = nullptr;
|
||||
QPalette m_palette;
|
||||
|
||||
|
||||
QMap<QString, QWidget*> m_tabMap;
|
||||
|
||||
bool removeWidget(QWidget * widget);
|
||||
bool m_hasSubTabs;
|
||||
bool m_isSecondary;
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void onRemoveTab(QObject *object);
|
||||
|
||||
|
||||
|
||||
void onCheckTabBarVisibility();
|
||||
|
||||
|
||||
|
||||
void slotTabCloseRequested(int index);
|
||||
|
||||
void slotCurrentChanged(int newIdx);
|
||||
|
||||
void slotMaximizeButtonClicked();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void addWidget(const QString &fullName, QWidget *widget, bool setClosable, bool focusNewTab = true);
|
||||
|
||||
|
||||
|
||||
QWidget *getWidget(const QString &fullName);
|
||||
|
||||
|
||||
|
||||
bool focusWidget(const QString &fullName);
|
||||
|
||||
|
||||
|
||||
void slotWindowTitleChanged(const QString &title);
|
||||
|
||||
void closeRequestTabWidget(LtsTabWidget *tabWidget);
|
||||
|
||||
QPoint startPos;
|
||||
LtsTabBar *m_tabbar = nullptr;
|
||||
QPalette m_palette;
|
||||
|
||||
|
||||
QMap<QString, QWidget *> m_tabMap;
|
||||
|
||||
|
||||
bool m_hasSubTabs;
|
||||
bool m_isSecondary;
|
||||
|
||||
QByteArray m_mainSplitterState;
|
||||
QByteArray m_mainSplitterState;
|
||||
};
|
||||
|
||||
|
||||
class CloseButton : public QAbstractButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using QAbstractButton::QAbstractButton;
|
||||
public:
|
||||
using QAbstractButton::QAbstractButton;
|
||||
|
||||
void setFontColor(const QColor &fontColor) { m_fontColor = fontColor; }
|
||||
QRectF cross() const;
|
||||
QLineF line() const;
|
||||
void setFontColor(const QColor& fontColor)
|
||||
{
|
||||
m_fontColor = fontColor;
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
QSize sizeHint() const override;
|
||||
QRectF cross() const;
|
||||
QLineF line() const;
|
||||
|
||||
private:
|
||||
QColor m_fontColor;
|
||||
bool m_isPressed = false;
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
void mouseReleaseEvent(QMouseEvent* e) override;
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
private:
|
||||
QColor m_fontColor;
|
||||
bool m_isPressed = false;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+58
-65
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_text_edit_dialog.h"
|
||||
|
||||
#include "lts_text_editor.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
@@ -15,123 +15,116 @@
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
LtsTextEditDialog::LtsTextEditDialog(QWidget *parent)
|
||||
: LtsDialog(parent, ButtonCombination::OkApplyCancel)
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
, m_textEditor(new LtsTextEditor(this))
|
||||
#else
|
||||
, m_textEditor2(new LtsTextEditor2(this))
|
||||
#endif
|
||||
{
|
||||
QHBoxLayout *hbox = new QHBoxLayout(this);
|
||||
LtsTextEditDialog::LtsTextEditDialog(QWidget* parent)
|
||||
: LtsDialog(parent, ButtonCombination::OkApplyCancel)
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
hbox->addWidget(m_textEditor);
|
||||
connect(m_textEditor->textEdit(), &QTextEdit::textChanged, this, [this]() {
|
||||
emit signalTextChanged(this->getHtmlText());
|
||||
});
|
||||
connect(m_textEditor, &LtsTextEditor::backgroundColorChanged,
|
||||
this, &LtsTextEditDialog::onBackgroundColorChanged);
|
||||
,
|
||||
m_textEditor(new LtsTextEditor(this))
|
||||
#else
|
||||
hbox->addWidget(m_textEditor2);
|
||||
connect(m_textEditor2->textEdit(), &QTextEdit::textChanged, this, [this]() {
|
||||
emit signalTextChanged(this->getHtmlText());
|
||||
});
|
||||
connect(m_textEditor2, &LtsTextEditor2::backgroundColorChanged,
|
||||
this, &LtsTextEditDialog::onBackgroundColorChanged);
|
||||
,
|
||||
m_textEditor2(new LtsTextEditor2(this))
|
||||
#endif
|
||||
{
|
||||
QHBoxLayout* hbox = new QHBoxLayout(this);
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
hbox->addWidget(m_textEditor);
|
||||
connect(m_textEditor->textEdit(), &QTextEdit::textChanged, this,
|
||||
[this]() { emit signalTextChanged(this->getHtmlText()); });
|
||||
connect(m_textEditor, &LtsTextEditor::backgroundColorChanged, this, &LtsTextEditDialog::onBackgroundColorChanged);
|
||||
#else
|
||||
hbox->addWidget(m_textEditor2);
|
||||
connect(m_textEditor2->textEdit(), &QTextEdit::textChanged, this,
|
||||
[this]() { emit signalTextChanged(this->getHtmlText()); });
|
||||
connect(m_textEditor2, &LtsTextEditor2::backgroundColorChanged, this, &LtsTextEditDialog::onBackgroundColorChanged);
|
||||
#endif
|
||||
|
||||
|
||||
enableBackgroundColor(false);
|
||||
enableBackgroundColor(false);
|
||||
}
|
||||
|
||||
LtsTextEditDialog::~LtsTextEditDialog()
|
||||
{}
|
||||
LtsTextEditDialog::~LtsTextEditDialog() {}
|
||||
|
||||
void LtsTextEditDialog::enableBackgroundColor(bool onOff)
|
||||
{
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
m_textEditor->enableBackgroundColor(onOff);
|
||||
m_textEditor->enableBackgroundColor(onOff);
|
||||
#else
|
||||
m_textEditor2->enableBackgroundColor(onOff);
|
||||
m_textEditor2->enableBackgroundColor(onOff);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void LtsTextEditDialog::retranslate()
|
||||
{
|
||||
|
||||
QString name = tr("Edit Text");
|
||||
translate(name);
|
||||
|
||||
QString name = tr("Edit Text");
|
||||
translate(name);
|
||||
}
|
||||
|
||||
bool LtsTextEditDialog::apply()
|
||||
{
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
QString textHtml = m_textEditor->textEdit()->document()->toHtml();
|
||||
const QString backGroundColor = QLatin1String("background-color:'%1'; ").arg(m_textEditor->backgroundColor().name());
|
||||
QString textHtml = m_textEditor->textEdit()->document()->toHtml();
|
||||
const QString backGroundColor =
|
||||
QLatin1String("background-color:'%1'; ").arg(m_textEditor->backgroundColor().name());
|
||||
|
||||
#else
|
||||
QString textHtml = m_textEditor2->textEdit()->document()->toHtml();
|
||||
const QString backGroundColor = QLatin1String("background-color:'%1'; ").arg(m_textEditor2->backgroundColor().name());
|
||||
QString textHtml = m_textEditor2->textEdit()->document()->toHtml();
|
||||
const QString backGroundColor =
|
||||
QLatin1String("background-color:'%1'; ").arg(m_textEditor2->backgroundColor().name());
|
||||
#endif
|
||||
|
||||
emit signalTextApplied(textHtml);
|
||||
emit signalTextApplied(textHtml);
|
||||
|
||||
const int insertBackGroundColorIndex = textHtml.indexOf(QLatin1String("font-family"));
|
||||
textHtml.insert(insertBackGroundColorIndex, backGroundColor);
|
||||
const int insertBackGroundColorIndex = textHtml.indexOf(QLatin1String("font-family"));
|
||||
textHtml.insert(insertBackGroundColorIndex, backGroundColor);
|
||||
|
||||
emit signalTextAppliedWithBackGroundColor(textHtml);
|
||||
emit signalTextAppliedWithBackGroundColor(textHtml);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LtsTextEditDialog::setHtml(const QString &htmlText)
|
||||
void LtsTextEditDialog::setHtml(const QString& htmlText)
|
||||
{
|
||||
|
||||
|
||||
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
m_textEditor->textEdit()->document()->setHtml(htmlText);
|
||||
m_textEditor->textEdit()->document()->setHtml(htmlText);
|
||||
#else
|
||||
m_textEditor2->textEdit()->document()->setHtml(htmlText);
|
||||
m_textEditor2->textEdit()->document()->setHtml(htmlText);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString LtsTextEditDialog::getHtmlText() const
|
||||
{
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
if(m_textEditor && m_textEditor->textEdit() && m_textEditor->textEdit()->document())
|
||||
return m_textEditor->textEdit()->document()->toHtml();
|
||||
if (m_textEditor && m_textEditor->textEdit() && m_textEditor->textEdit()->document())
|
||||
return m_textEditor->textEdit()->document()->toHtml();
|
||||
#else
|
||||
if(m_textEditor2 && m_textEditor2->textEdit() && m_textEditor2->textEdit()->document())
|
||||
return m_textEditor2->textEdit()->document()->toHtml();
|
||||
if (m_textEditor2 && m_textEditor2->textEdit() && m_textEditor2->textEdit()->document())
|
||||
return m_textEditor2->textEdit()->document()->toHtml();
|
||||
#endif
|
||||
return {};
|
||||
return {};
|
||||
}
|
||||
|
||||
void LtsTextEditDialog::setInitialBackgroundColor(const QColor &bgColor)
|
||||
void LtsTextEditDialog::setInitialBackgroundColor(const QColor& bgColor)
|
||||
{
|
||||
#ifdef USE_TEXT_EDITOR
|
||||
if (m_textEditor)
|
||||
m_textEditor->setInitialBackgroundColor(bgColor);
|
||||
if (m_textEditor)
|
||||
m_textEditor->setInitialBackgroundColor(bgColor);
|
||||
#else
|
||||
if (m_textEditor2)
|
||||
m_textEditor2->setInitialBackgroundColor(bgColor);
|
||||
if (m_textEditor2)
|
||||
m_textEditor2->setInitialBackgroundColor(bgColor);
|
||||
#endif
|
||||
}
|
||||
|
||||
void LtsTextEditDialog::dialogCanceled()
|
||||
{
|
||||
emit signalDialogCanceled();
|
||||
BaseClass::dialogCanceled();
|
||||
emit signalDialogCanceled();
|
||||
BaseClass::dialogCanceled();
|
||||
}
|
||||
|
||||
void LtsTextEditDialog::onBackgroundColorChanged(const QColor &backgroundColor)
|
||||
void LtsTextEditDialog::onBackgroundColorChanged(const QColor& backgroundColor)
|
||||
{
|
||||
slotChangesMade();
|
||||
emit signalBackgroundColorChanged(backgroundColor);
|
||||
slotChangesMade();
|
||||
emit signalBackgroundColorChanged(backgroundColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+27
-34
@@ -1,56 +1,49 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsWidgets/lts_text_editor.h>
|
||||
#include <LtsWidgets/lts_text_editor2.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTextEditDialog : public LtsWidgets::LtsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
using BaseClass = LtsWidgets::LtsDialog;
|
||||
using BaseClass = LtsWidgets::LtsDialog;
|
||||
|
||||
public:
|
||||
LtsTextEditDialog(QWidget *parent = nullptr);
|
||||
~LtsTextEditDialog();
|
||||
public:
|
||||
LtsTextEditDialog(QWidget* parent = nullptr);
|
||||
~LtsTextEditDialog();
|
||||
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor &bgColor);
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor& bgColor);
|
||||
|
||||
void retranslate() override;
|
||||
bool apply() override;
|
||||
void setHtml(const QString &htmlText);
|
||||
QString getHtmlText() const;
|
||||
void retranslate() override;
|
||||
bool apply() override;
|
||||
void setHtml(const QString& htmlText);
|
||||
QString getHtmlText() const;
|
||||
|
||||
protected:
|
||||
void dialogCanceled() override;
|
||||
protected:
|
||||
void dialogCanceled() override;
|
||||
|
||||
private:
|
||||
LtsTextEditor *m_textEditor{nullptr};
|
||||
LtsTextEditor2 *m_textEditor2{nullptr};
|
||||
private:
|
||||
LtsTextEditor* m_textEditor{nullptr};
|
||||
LtsTextEditor2* m_textEditor2{nullptr};
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onBackgroundColorChanged(const QColor& backgroundColor);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onBackgroundColorChanged(const QColor &backgroundColor);
|
||||
|
||||
Q_SIGNALS:
|
||||
void signalTextChanged(const QString &htmlText);
|
||||
void signalTextApplied(const QString &htmlText);
|
||||
void signalTextAppliedWithBackGroundColor(const QString &htmlText);
|
||||
void signalBackgroundColorChanged(const QColor &bgColor);
|
||||
void signalDialogApplied();
|
||||
void signalDialogCanceled();
|
||||
|
||||
Q_SIGNALS:
|
||||
void signalTextChanged(const QString& htmlText);
|
||||
void signalTextApplied(const QString& htmlText);
|
||||
void signalTextAppliedWithBackGroundColor(const QString& htmlText);
|
||||
void signalBackgroundColorChanged(const QColor& bgColor);
|
||||
void signalDialogApplied();
|
||||
void signalDialogCanceled();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+34
-39
@@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsTextEditor;
|
||||
@@ -14,49 +12,46 @@ class LtsTextEditor;
|
||||
class QTextEdit;
|
||||
class QTextCharFormat;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTextEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LtsTextEditor(QWidget *parent = nullptr);
|
||||
~LtsTextEditor();
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor &bgColor);
|
||||
QTextEdit *textEdit();
|
||||
QColor backgroundColor() const;
|
||||
Q_OBJECT
|
||||
public:
|
||||
LtsTextEditor(QWidget* parent = nullptr);
|
||||
~LtsTextEditor();
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor& bgColor);
|
||||
QTextEdit* textEdit();
|
||||
QColor backgroundColor() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void backgroundColorChanged(const QColor &bgColor);
|
||||
Q_SIGNALS:
|
||||
void backgroundColorChanged(const QColor& bgColor);
|
||||
|
||||
private:
|
||||
Ui::LtsTextEditor *m_ui;
|
||||
QColor m_backgroundColor{Qt::white};
|
||||
QColor m_foregroundColor{Qt::black};
|
||||
private:
|
||||
Ui::LtsTextEditor* m_ui;
|
||||
QColor m_backgroundColor{Qt::white};
|
||||
QColor m_foregroundColor{Qt::black};
|
||||
|
||||
private slots:
|
||||
void slotCurrentCharFormatChanged(const QTextCharFormat &format);
|
||||
void slotFontChanged(const QFont &f);
|
||||
void slotTextColorChanged(const QColor &c);
|
||||
void slotBackgroundColorChanged(const QColor &bgColor);
|
||||
void slotAlignmentChanged();
|
||||
void slotMergeFormatOnWordOrSelection(const QTextCharFormat &format);
|
||||
void slotClipboardDataChanged();
|
||||
void slotTextColor();
|
||||
void slotBackgroundColor();
|
||||
void slotTextSize(const QString &p);
|
||||
void slotTextSizeEditingFinished();
|
||||
void slotTextFamily(const QString &f);
|
||||
void slotTextItalic();
|
||||
void slotTextUnderline();
|
||||
void slotTextBold();
|
||||
|
||||
void slotTextAlign();
|
||||
private slots:
|
||||
void slotCurrentCharFormatChanged(const QTextCharFormat& format);
|
||||
void slotFontChanged(const QFont& f);
|
||||
void slotTextColorChanged(const QColor& c);
|
||||
void slotBackgroundColorChanged(const QColor& bgColor);
|
||||
void slotAlignmentChanged();
|
||||
void slotMergeFormatOnWordOrSelection(const QTextCharFormat& format);
|
||||
void slotClipboardDataChanged();
|
||||
void slotTextColor();
|
||||
void slotBackgroundColor();
|
||||
void slotTextSize(const QString& p);
|
||||
void slotTextSizeEditingFinished();
|
||||
void slotTextFamily(const QString& f);
|
||||
void slotTextItalic();
|
||||
void slotTextUnderline();
|
||||
void slotTextBold();
|
||||
|
||||
void slotTextAlign();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+92
-92
@@ -1,18 +1,16 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QtPrintSupport/QPrinter>
|
||||
#include <QtPrintSupport/QPrintPreviewDialog>
|
||||
#include <QtPrintSupport/QPrinter>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
@@ -29,108 +27,110 @@ namespace LtsWidgets
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsTextEditor2 : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsTextEditor2(QWidget *parent = nullptr);
|
||||
~LtsTextEditor2();
|
||||
public:
|
||||
explicit LtsTextEditor2(QWidget* parent = nullptr);
|
||||
~LtsTextEditor2();
|
||||
|
||||
static QString rsrcPath(){return (QStringLiteral(":/images/win"));}
|
||||
static QString rsrcPath()
|
||||
{
|
||||
return (QStringLiteral(":/images/win"));
|
||||
}
|
||||
|
||||
QColor m_backgroundColor{Qt::white};
|
||||
QColor m_foregroundColor{Qt::black};
|
||||
QColor m_backgroundColor{Qt::white};
|
||||
QColor m_foregroundColor{Qt::black};
|
||||
|
||||
QTextEdit *textEdit();
|
||||
QColor backgroundColor() const;
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor &bgColor);
|
||||
bool load(const QString &f);
|
||||
QTextEdit* textEdit();
|
||||
QColor backgroundColor() const;
|
||||
void enableBackgroundColor(bool onOff);
|
||||
void setInitialBackgroundColor(const QColor& bgColor);
|
||||
bool load(const QString& f);
|
||||
|
||||
Q_SIGNALS:
|
||||
void backgroundColorChanged(const QColor& bgColor);
|
||||
|
||||
Q_SIGNALS:
|
||||
void backgroundColorChanged(const QColor &bgColor);
|
||||
public slots:
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void onFileNew();
|
||||
void onFileOpen();
|
||||
bool onFileSave();
|
||||
bool onFileSaveAs();
|
||||
void onFilePrint();
|
||||
void onFilePrintPreview();
|
||||
void onFilePrintPdf();
|
||||
|
||||
private slots:
|
||||
void onFileNew();
|
||||
void onFileOpen();
|
||||
bool onFileSave();
|
||||
bool onFileSaveAs();
|
||||
void onFilePrint();
|
||||
void onFilePrintPreview();
|
||||
void onFilePrintPdf();
|
||||
void onTextBold();
|
||||
void onTextUnderline();
|
||||
void onTextItalic();
|
||||
void onTextFamily(const QString& f);
|
||||
void onTextSize(const QString& p);
|
||||
void onTextStyle(int styleIndex);
|
||||
void onTextColor();
|
||||
void onTextAlign(QAction* a);
|
||||
void setChecked(bool checked);
|
||||
void indent();
|
||||
void unindent();
|
||||
void slotBackgroundColorChanged(const QColor& bgColor);
|
||||
void slotBackgroundColor();
|
||||
|
||||
void onTextBold();
|
||||
void onTextUnderline();
|
||||
void onTextItalic();
|
||||
void onTextFamily(const QString &f);
|
||||
void onTextSize(const QString &p);
|
||||
void onTextStyle(int styleIndex);
|
||||
void onTextColor();
|
||||
void onTextAlign(QAction *a);
|
||||
void setChecked(bool checked);
|
||||
void indent();
|
||||
void unindent();
|
||||
void slotBackgroundColorChanged(const QColor &bgColor);
|
||||
void slotBackgroundColor();
|
||||
void currentCharFormatChanged(const QTextCharFormat& format);
|
||||
void cursorPositionChanged();
|
||||
|
||||
void currentCharFormatChanged(const QTextCharFormat &format);
|
||||
void cursorPositionChanged();
|
||||
void clipboardDataChanged();
|
||||
void about();
|
||||
void printPreview(QPrinter*);
|
||||
|
||||
void clipboardDataChanged();
|
||||
void about();
|
||||
void printPreview(QPrinter *);
|
||||
private:
|
||||
void setupFileActions();
|
||||
void setupEditActions();
|
||||
void setupTextActions();
|
||||
bool maybeSave();
|
||||
void setCurrentFileName(const QString& fileName);
|
||||
void modifyIndentation(int amount);
|
||||
|
||||
private:
|
||||
void setupFileActions();
|
||||
void setupEditActions();
|
||||
void setupTextActions();
|
||||
bool maybeSave();
|
||||
void setCurrentFileName(const QString &fileName);
|
||||
void modifyIndentation(int amount);
|
||||
void mergeFormatOnWordOrSelection(const QTextCharFormat& format);
|
||||
void fontChanged(const QFont& f);
|
||||
void colorChanged(const QColor& c);
|
||||
void alignmentChanged(Qt::Alignment a);
|
||||
|
||||
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
|
||||
void fontChanged(const QFont &f);
|
||||
void colorChanged(const QColor &c);
|
||||
void alignmentChanged(Qt::Alignment a);
|
||||
|
||||
QAction *m_actionSave;
|
||||
QAction *m_actionOpen;
|
||||
QAction *m_actionQuit;
|
||||
QAction *m_actionSaveAs;
|
||||
QAction *m_actionNew;
|
||||
QAction *m_actionPrint;
|
||||
QAction *m_actionPreview;
|
||||
QAction *m_actionExport;
|
||||
QAction *m_actionTextBold;
|
||||
QAction *m_actionTextUnderline;
|
||||
QAction *m_actionTextItalic;
|
||||
QAction *m_actionTextColor;
|
||||
QAction *m_actionBackgroundColor;
|
||||
QAction *m_actionAlignLeft;
|
||||
QAction *m_actionAlignCenter;
|
||||
QAction *m_actionAlignRight;
|
||||
QAction *m_actionAlignJustify;
|
||||
QAction *m_actionIndentLess;
|
||||
QAction *m_actionIndentMore;
|
||||
QAction *m_actionToggleCheckState;
|
||||
QAction *m_actionUndo;
|
||||
QAction *m_actionRedo;
|
||||
QAction* m_actionSave;
|
||||
QAction* m_actionOpen;
|
||||
QAction* m_actionQuit;
|
||||
QAction* m_actionSaveAs;
|
||||
QAction* m_actionNew;
|
||||
QAction* m_actionPrint;
|
||||
QAction* m_actionPreview;
|
||||
QAction* m_actionExport;
|
||||
QAction* m_actionTextBold;
|
||||
QAction* m_actionTextUnderline;
|
||||
QAction* m_actionTextItalic;
|
||||
QAction* m_actionTextColor;
|
||||
QAction* m_actionBackgroundColor;
|
||||
QAction* m_actionAlignLeft;
|
||||
QAction* m_actionAlignCenter;
|
||||
QAction* m_actionAlignRight;
|
||||
QAction* m_actionAlignJustify;
|
||||
QAction* m_actionIndentLess;
|
||||
QAction* m_actionIndentMore;
|
||||
QAction* m_actionToggleCheckState;
|
||||
QAction* m_actionUndo;
|
||||
QAction* m_actionRedo;
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
QAction *m_actionCut;
|
||||
QAction *m_actionCopy;
|
||||
QAction *m_actionPaste;
|
||||
QAction* m_actionCut;
|
||||
QAction* m_actionCopy;
|
||||
QAction* m_actionPaste;
|
||||
#endif
|
||||
|
||||
QComboBox *m_comboStyle;
|
||||
QAction *m_comboStyleAction;
|
||||
QFontComboBox *m_comboFont;
|
||||
QComboBox *m_comboSize;
|
||||
QComboBox* m_comboStyle;
|
||||
QAction* m_comboStyleAction;
|
||||
QFontComboBox* m_comboFont;
|
||||
QComboBox* m_comboSize;
|
||||
|
||||
QToolBar *m_tb;
|
||||
QString m_fileName;
|
||||
QTextEdit *m_textEdit;
|
||||
QToolBar* m_tb;
|
||||
QString m_fileName;
|
||||
QTextEdit* m_textEdit;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+75
-73
@@ -1,16 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVector>
|
||||
#include <QShortcut>
|
||||
#include <QMap>
|
||||
|
||||
#include <QObject>
|
||||
#include <QShortcut>
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
class QMenu;
|
||||
class QLabel;
|
||||
@@ -26,91 +23,96 @@ class LtsDragIcon;
|
||||
|
||||
struct ShortCut
|
||||
{
|
||||
int key = 0;
|
||||
QShortcut *shortcut = nullptr;
|
||||
QString name;
|
||||
QString identifier;
|
||||
LtsDragIcon *icon = nullptr;
|
||||
QString keyName() const {return shortcut ? shortcut->key().toString() : QString();}
|
||||
void clear();
|
||||
int key = 0;
|
||||
QShortcut* shortcut = nullptr;
|
||||
QString name;
|
||||
QString identifier;
|
||||
LtsDragIcon* icon = nullptr;
|
||||
|
||||
explicit ShortCut(QWidget *parent = nullptr)
|
||||
: shortcut(new QShortcut(parent))
|
||||
{}
|
||||
|
||||
~ShortCut() { delete shortcut; }
|
||||
ShortCut(const ShortCut &o)
|
||||
: key(o.key)
|
||||
, name(o.name)
|
||||
, identifier(o.identifier)
|
||||
, icon(o.icon)
|
||||
{
|
||||
if (o.shortcut)
|
||||
QString keyName() const
|
||||
{
|
||||
delete shortcut;
|
||||
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr, o.shortcut->context());
|
||||
return shortcut ? shortcut->key().toString() : QString();
|
||||
}
|
||||
}
|
||||
|
||||
ShortCut &operator=(const ShortCut &o)
|
||||
{
|
||||
if (&o == this)
|
||||
return *this;
|
||||
void clear();
|
||||
|
||||
key = o.key;
|
||||
name = o.name;
|
||||
identifier = o.identifier;
|
||||
icon = o.icon;
|
||||
QWidget *parent = qobject_cast<QWidget*>(shortcut->parent());
|
||||
delete shortcut;
|
||||
if (o.shortcut)
|
||||
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr, o.shortcut->context());
|
||||
else
|
||||
shortcut = new QShortcut(parent);
|
||||
return *this;
|
||||
}
|
||||
explicit ShortCut(QWidget* parent = nullptr) : shortcut(new QShortcut(parent)) {}
|
||||
|
||||
~ShortCut()
|
||||
{
|
||||
delete shortcut;
|
||||
}
|
||||
|
||||
ShortCut(const ShortCut& o) : key(o.key), name(o.name), identifier(o.identifier), icon(o.icon)
|
||||
{
|
||||
if (o.shortcut)
|
||||
{
|
||||
delete shortcut;
|
||||
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr,
|
||||
o.shortcut->context());
|
||||
}
|
||||
}
|
||||
|
||||
ShortCut& operator=(const ShortCut& o)
|
||||
{
|
||||
if (&o == this)
|
||||
return *this;
|
||||
|
||||
key = o.key;
|
||||
name = o.name;
|
||||
identifier = o.identifier;
|
||||
icon = o.icon;
|
||||
QWidget* parent = qobject_cast<QWidget*>(shortcut->parent());
|
||||
delete shortcut;
|
||||
if (o.shortcut)
|
||||
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr,
|
||||
o.shortcut->context());
|
||||
else
|
||||
shortcut = new QShortcut(parent);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsToolBarArea : public QWidget
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsToolBarArea(QWidget *parent = nullptr);
|
||||
~LtsToolBarArea();
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsToolBarArea(QWidget* parent = nullptr);
|
||||
~LtsToolBarArea();
|
||||
|
||||
void addMenuEntry(LtsDragIcon *entry, LtsDragIcon *after = nullptr);
|
||||
void clearToolBarArea();
|
||||
void addMenuEntry(LtsDragIcon* entry, LtsDragIcon* after = nullptr);
|
||||
void clearToolBarArea();
|
||||
|
||||
void setMenuEntries(const QVector<LtsDragIcon *> &actions);
|
||||
QStringList menuEntries() const;
|
||||
void setMenuEntries(const QVector<LtsDragIcon*>& actions);
|
||||
QStringList menuEntries() const;
|
||||
|
||||
bool setFunctionKey(int fkey, const QString &action);
|
||||
QMap<int, QString> functionKeys() const;
|
||||
bool setFunctionKey(int fkey, const QString& action);
|
||||
QMap<int, QString> functionKeys() const;
|
||||
|
||||
bool removeFunctionKey(const QString &action);
|
||||
void removeMenuAction(LtsDragIcon *icon);
|
||||
bool removeFunctionKey(const QString& action);
|
||||
void removeMenuAction(LtsDragIcon* icon);
|
||||
|
||||
public slots:
|
||||
void showContextMenu(const QPoint &pos);
|
||||
void functionKeyMenuTriggered();
|
||||
public slots:
|
||||
void showContextMenu(const QPoint& pos);
|
||||
void functionKeyMenuTriggered();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
QMenu* functionKeyMenu(QWidget *parent);
|
||||
QString m_currentIdentifierForContextMenue;
|
||||
private:
|
||||
QMenu* functionKeyMenu(QWidget* parent);
|
||||
QString m_currentIdentifierForContextMenue;
|
||||
|
||||
QVector<LtsDragIcon *> m_buttonMap;
|
||||
QVector<LtsDragIcon *> m_foreignButtonMap;
|
||||
QMap<int, ShortCut> m_functionKeys;
|
||||
QLabel *m_dummyLabel;
|
||||
QVector<LtsDragIcon*> m_buttonMap;
|
||||
QVector<LtsDragIcon*> m_foreignButtonMap;
|
||||
QMap<int, ShortCut> m_functionKeys;
|
||||
QLabel* m_dummyLabel;
|
||||
|
||||
Ui::LtsToolBarArea *m_ui;
|
||||
Ui::LtsToolBarArea* m_ui;
|
||||
|
||||
void saveSettings();
|
||||
void saveSettings();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+40
-55
@@ -1,85 +1,70 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_tool_box.h"
|
||||
|
||||
#include "lts_drag_icon.h"
|
||||
#include "lts_grid_layout.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QScroller>
|
||||
#include <QScrollArea>
|
||||
#include <QScroller>
|
||||
|
||||
using namespace LtsWidgets;
|
||||
|
||||
|
||||
LtsToolBox::LtsToolBox(QWidget *parent)
|
||||
: QToolBox(parent)
|
||||
LtsToolBox::LtsToolBox(QWidget* parent) : QToolBox(parent)
|
||||
{
|
||||
|
||||
setMinimumSize(17, 200);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &LtsToolBox::customContextMenuRequested,
|
||||
this, &LtsToolBox::showContextMenu);
|
||||
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
setMinimumSize(17, 200);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &LtsToolBox::customContextMenuRequested, this, &LtsToolBox::showContextMenu);
|
||||
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
}
|
||||
|
||||
LtsToolBox::~LtsToolBox()
|
||||
LtsToolBox::~LtsToolBox() {}
|
||||
|
||||
void LtsToolBox::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
emit resized(e);
|
||||
QToolBox::resizeEvent(e);
|
||||
}
|
||||
|
||||
void LtsToolBox::resizeEvent(QResizeEvent *e)
|
||||
void LtsToolBox::addItem(QWidget* widget, const QString& text)
|
||||
{
|
||||
emit resized(e);
|
||||
QToolBox::resizeEvent(e);
|
||||
|
||||
setMinimumSize(120, 100);
|
||||
QToolBox::addItem(widget, text);
|
||||
}
|
||||
|
||||
void LtsToolBox::addItem(QWidget *widget, const QString &text)
|
||||
{
|
||||
setMinimumSize(120, 100);
|
||||
QToolBox::addItem(widget, text);
|
||||
}
|
||||
|
||||
|
||||
void LtsToolBox::showContextMenu(const QPoint &pos)
|
||||
void LtsToolBox::showContextMenu(const QPoint& pos)
|
||||
{
|
||||
|
||||
|
||||
QPoint globalPos = this->mapToGlobal(pos);
|
||||
|
||||
|
||||
QPoint globalPos = this->mapToGlobal(pos);
|
||||
|
||||
QMenu myMenu;
|
||||
myMenu.addAction(tr("Icon and Text"));
|
||||
QAction *to = myMenu.addAction(tr("Text Only"));
|
||||
QAction *io = myMenu.addAction(tr("Icon Only"));
|
||||
QMenu myMenu;
|
||||
myMenu.addAction(tr("Icon and Text"));
|
||||
QAction* to = myMenu.addAction(tr("Text Only"));
|
||||
QAction* io = myMenu.addAction(tr("Icon Only"));
|
||||
|
||||
|
||||
QAction *selectedItem = myMenu.exec(globalPos);
|
||||
if (selectedItem)
|
||||
{
|
||||
ButtonStyle newStyle = ButtonStyle::eTextNextToIcon;
|
||||
if (selectedItem == to)
|
||||
newStyle = ButtonStyle::eTextOnly;
|
||||
if (selectedItem == io)
|
||||
newStyle = ButtonStyle::eIconOnly;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
QAction* selectedItem = myMenu.exec(globalPos);
|
||||
if (selectedItem)
|
||||
{
|
||||
const QList<LtsDragIcon *> list = widget(i)->findChildren<LtsDragIcon *>();
|
||||
for (LtsDragIcon *icon : list)
|
||||
icon->setButtonStyle(newStyle);
|
||||
LtsGridLayout *lay = qobject_cast<LtsGridLayout *>(widget(i)->layout());
|
||||
if (lay)
|
||||
lay->setAutoSize((newStyle == ButtonStyle::eIconOnly));
|
||||
}
|
||||
ButtonStyle newStyle = ButtonStyle::eTextNextToIcon;
|
||||
if (selectedItem == to)
|
||||
newStyle = ButtonStyle::eTextOnly;
|
||||
if (selectedItem == io)
|
||||
newStyle = ButtonStyle::eIconOnly;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
const QList<LtsDragIcon*> list = widget(i)->findChildren<LtsDragIcon*>();
|
||||
for (LtsDragIcon* icon : list)
|
||||
icon->setButtonStyle(newStyle);
|
||||
LtsGridLayout* lay = qobject_cast<LtsGridLayout*>(widget(i)->layout());
|
||||
if (lay)
|
||||
lay->setAutoSize((newStyle == ButtonStyle::eIconOnly));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
Executable → Regular
+12
-15
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "lts_base.h"
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QToolBox>
|
||||
|
||||
namespace LtsWidgets
|
||||
@@ -14,19 +12,18 @@ namespace LtsWidgets
|
||||
|
||||
class LTSWIDGETS_EXPORT LtsToolBox : public QToolBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsToolBox(QWidget *parent = nullptr);
|
||||
~LtsToolBox();
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void addItem(QWidget *widget, const QString &text);
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsToolBox(QWidget* parent = nullptr);
|
||||
~LtsToolBox();
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
void addItem(QWidget* widget, const QString& text);
|
||||
|
||||
signals:
|
||||
void resized(QResizeEvent *e);
|
||||
|
||||
public slots:
|
||||
void showContextMenu(const QPoint &pos);
|
||||
signals:
|
||||
void resized(QResizeEvent* e);
|
||||
|
||||
public slots:
|
||||
void showContextMenu(const QPoint& pos);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+5
-6
@@ -1,17 +1,16 @@
|
||||
#include "lts_wait_dialog.h"
|
||||
#include "lts_global_wait_dialog.h"
|
||||
|
||||
#include "lts_global_wait_dialog.h"
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
LtsWaitDialog::LtsWaitDialog(const QString &customText)
|
||||
LtsWaitDialog::LtsWaitDialog(const QString& customText)
|
||||
{
|
||||
LtsGlobalWaitDialog::getInstance()->wait(customText);
|
||||
LtsGlobalWaitDialog::getInstance()->wait(customText);
|
||||
}
|
||||
|
||||
|
||||
LtsWaitDialog::~LtsWaitDialog()
|
||||
{
|
||||
LtsGlobalWaitDialog::getInstance()->done();
|
||||
}
|
||||
LtsGlobalWaitDialog::getInstance()->done();
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+4
-6
@@ -3,19 +3,17 @@
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LTSWIDGETS_EXPORT LtsWaitDialog
|
||||
{
|
||||
public:
|
||||
LtsWaitDialog(const QString &customText = {});
|
||||
~LtsWaitDialog();
|
||||
public:
|
||||
LtsWaitDialog(const QString& customText = {});
|
||||
~LtsWaitDialog();
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<LtsWaitDialog> LtsWaitDialogContainer;
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef LTSWIDGETS_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSWIDGETS_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSWIDGETS_LIB)
|
||||
# define LTSWIDGETS_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSWIDGETS_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define LTSWIDGETS_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_LTSWIDGETS_LIB)
|
||||
#define LTSWIDGETS_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define LTSWIDGETS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+251
-122
File diff suppressed because it is too large.
Load diff
Executable → Regular
+87
-98
@@ -1,153 +1,142 @@
|
||||
|
||||
|
||||
|
||||
#include "requirement_widget.h"
|
||||
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
UiRequirement::UiRequirement(QLabel *descriptionLabel, const std::function<bool()> &requirementCheck, const QString &userWarningMessage)
|
||||
: m_descriptionLabel(descriptionLabel)
|
||||
, m_requirementCheck(requirementCheck)
|
||||
, m_lastResult(true)
|
||||
, m_userWarningMessage(userWarningMessage)
|
||||
UiRequirement::UiRequirement(QLabel* descriptionLabel, const std::function<bool()>& requirementCheck,
|
||||
const QString& userWarningMessage)
|
||||
: m_descriptionLabel(descriptionLabel), m_requirementCheck(requirementCheck), m_lastResult(true),
|
||||
m_userWarningMessage(userWarningMessage)
|
||||
{
|
||||
retranslate();
|
||||
retranslate();
|
||||
}
|
||||
|
||||
|
||||
void UiRequirement::reset()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
m_descriptionLabel->setText(m_originalText);
|
||||
m_descriptionLabel->setToolTip(m_originalTooltip);
|
||||
if (!isValid())
|
||||
return;
|
||||
m_descriptionLabel->setText(m_originalText);
|
||||
m_descriptionLabel->setToolTip(m_originalTooltip);
|
||||
}
|
||||
|
||||
|
||||
void UiRequirement::setTexts()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
if (!m_lastResult)
|
||||
{
|
||||
m_descriptionLabel->setText(QStringLiteral("<span style=\"color:#aa0000;\">\u2022 %1</span>").arg(m_originalText));
|
||||
|
||||
if (!m_userWarningMessage.isEmpty())
|
||||
if (!isValid())
|
||||
return;
|
||||
if (!m_lastResult)
|
||||
{
|
||||
m_descriptionLabel->setCursor(Qt::WhatsThisCursor);
|
||||
m_descriptionLabel->setToolTip(m_userWarningMessage);
|
||||
m_descriptionLabel->setText(
|
||||
QStringLiteral("<span style=\"color:#aa0000;\">\u2022 %1</span>").arg(m_originalText));
|
||||
|
||||
if (!m_userWarningMessage.isEmpty())
|
||||
{
|
||||
m_descriptionLabel->setCursor(Qt::WhatsThisCursor);
|
||||
m_descriptionLabel->setToolTip(m_userWarningMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
else
|
||||
{
|
||||
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
|
||||
m_descriptionLabel->setText(QStringLiteral("\u2022 %1").arg(m_originalText));
|
||||
m_descriptionLabel->setCursor(Qt::ArrowCursor);
|
||||
m_descriptionLabel->setToolTip(m_originalTooltip);
|
||||
}
|
||||
m_descriptionLabel->setText(QStringLiteral("\u2022 %1").arg(m_originalText));
|
||||
m_descriptionLabel->setCursor(Qt::ArrowCursor);
|
||||
m_descriptionLabel->setToolTip(m_originalTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UiRequirement::retranslate()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
if (!isValid())
|
||||
return;
|
||||
|
||||
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
|
||||
auto x = m_descriptionLabel->text();
|
||||
if (x.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
auto x = m_descriptionLabel->text();
|
||||
if (x.startsWith(QStringLiteral("\u2022 ")))
|
||||
return;
|
||||
|
||||
m_originalText = x;
|
||||
m_originalText = x;
|
||||
|
||||
m_originalTooltip = m_descriptionLabel->toolTip();
|
||||
setTexts();
|
||||
m_originalTooltip = m_descriptionLabel->toolTip();
|
||||
setTexts();
|
||||
}
|
||||
|
||||
|
||||
bool UiRequirement::checkRequirement()
|
||||
{
|
||||
if (!isValid())
|
||||
return m_lastResult;
|
||||
if (!isValid())
|
||||
return m_lastResult;
|
||||
|
||||
m_lastResult = m_requirementCheck();
|
||||
m_lastResult = m_requirementCheck();
|
||||
|
||||
if (!m_descriptionLabel->isVisible() && !m_descriptionLabel->property("checkMe").toBool())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
setTexts();
|
||||
|
||||
return m_lastResult;
|
||||
}
|
||||
|
||||
|
||||
bool UiRequirementList::checkRequirements(QWidget *messageOnThisParent)
|
||||
{
|
||||
bool result = true;
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement &r = (*i);
|
||||
|
||||
|
||||
if (!r.isValid())
|
||||
continue;
|
||||
|
||||
if (!r.checkRequirement())
|
||||
if (!m_descriptionLabel->isVisible() && !m_descriptionLabel->property("checkMe").toBool())
|
||||
{
|
||||
result = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result && messageOnThisParent)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(messageOnThisParent,
|
||||
QApplication::translate("LtsWidgets::LtsDialog",
|
||||
"There are elements that have invalid or no value.<br>"
|
||||
"Please change values in the elements which are marked with red text."),
|
||||
QApplication::translate("LtsWidgets::LtsDialog", "Operation not complete"));
|
||||
}
|
||||
setTexts();
|
||||
|
||||
return result;
|
||||
return m_lastResult;
|
||||
}
|
||||
|
||||
|
||||
void UiRequirementList::addRequirement(const UiRequirement &uiRequirement)
|
||||
bool UiRequirementList::checkRequirements(QWidget* messageOnThisParent)
|
||||
{
|
||||
m_requirementList.append(uiRequirement);
|
||||
bool result = true;
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement& r = (*i);
|
||||
|
||||
if (!r.isValid())
|
||||
continue;
|
||||
|
||||
if (!r.checkRequirement())
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result && messageOnThisParent)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(
|
||||
messageOnThisParent,
|
||||
QApplication::translate("LtsWidgets::LtsDialog",
|
||||
"There are elements that have invalid or no value.<br>"
|
||||
"Please change values in the elements which are marked with red text."),
|
||||
QApplication::translate("LtsWidgets::LtsDialog", "Operation not complete"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void UiRequirementList::addRequirement(const UiRequirement& uiRequirement)
|
||||
{
|
||||
m_requirementList.append(uiRequirement);
|
||||
}
|
||||
|
||||
void UiRequirementList::clear()
|
||||
{
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement &uir = *i;
|
||||
uir.reset();
|
||||
}
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement& uir = *i;
|
||||
uir.reset();
|
||||
}
|
||||
|
||||
m_requirementList.clear();
|
||||
m_requirementList.clear();
|
||||
}
|
||||
|
||||
|
||||
void UiRequirementList::retranslate()
|
||||
{
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement &r = (*i);
|
||||
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
||||
{
|
||||
UiRequirement& r = (*i);
|
||||
|
||||
r.retranslate();
|
||||
}
|
||||
r.retranslate();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+30
-41
@@ -1,73 +1,62 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltswidgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
|
||||
class QLabel;
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT UiRequirement
|
||||
class LTSWIDGETS_EXPORT UiRequirement
|
||||
{
|
||||
public:
|
||||
explicit UiRequirement() = default;
|
||||
public:
|
||||
explicit UiRequirement() = default;
|
||||
|
||||
|
||||
UiRequirement(QLabel* descriptionLabel, const std::function<bool()>& requirementCheck,
|
||||
const QString& userWarningMessage = QString());
|
||||
|
||||
UiRequirement(QLabel *descriptionLabel, const std::function<bool()> &requirementCheck, const QString &userWarningMessage = QString());
|
||||
void reset();
|
||||
|
||||
void reset();
|
||||
bool checkRequirement();
|
||||
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return m_descriptionLabel != nullptr;
|
||||
}
|
||||
|
||||
bool checkRequirement();
|
||||
void retranslate();
|
||||
|
||||
bool isValid() const { return m_descriptionLabel != nullptr; }
|
||||
private:
|
||||
void setTexts();
|
||||
|
||||
void retranslate();
|
||||
|
||||
private:
|
||||
void setTexts();
|
||||
|
||||
QLabel *m_descriptionLabel;
|
||||
std::function<bool()> m_requirementCheck;
|
||||
QString m_originalText;
|
||||
QString m_originalTooltip;
|
||||
bool m_lastResult;
|
||||
QString m_userWarningMessage;
|
||||
QLabel* m_descriptionLabel;
|
||||
std::function<bool()> m_requirementCheck;
|
||||
QString m_originalText;
|
||||
QString m_originalTooltip;
|
||||
bool m_lastResult;
|
||||
QString m_userWarningMessage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSWIDGETS_EXPORT UiRequirementList
|
||||
{
|
||||
public:
|
||||
UiRequirementList() = default;
|
||||
public:
|
||||
UiRequirementList() = default;
|
||||
|
||||
|
||||
bool checkRequirements(QWidget* messageOnThisParent = nullptr);
|
||||
|
||||
bool checkRequirements(QWidget *messageOnThisParent = nullptr);
|
||||
void addRequirement(const UiRequirement& uiRequirement);
|
||||
|
||||
|
||||
void clear();
|
||||
|
||||
void addRequirement(const UiRequirement &uiRequirement);
|
||||
void retranslate();
|
||||
|
||||
void clear();
|
||||
|
||||
void retranslate();
|
||||
|
||||
private:
|
||||
QVector<UiRequirement> m_requirementList;
|
||||
private:
|
||||
QVector<UiRequirement> m_requirementList;
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+133
-139
@@ -1,221 +1,215 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_picture_editing.h"
|
||||
#include "ui_lts_picture_editing.h"
|
||||
#include "lts_picture_view.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QPixmap>
|
||||
#include <QMessageBox>
|
||||
#include <QImage>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include "lts_picture_view.h"
|
||||
#include "ui_lts_picture_editing.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QImage>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
|
||||
LtsPictureEditing::LtsPictureEditing(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, m_gvPicture(nullptr)
|
||||
, m_ui(new Ui::PictureEditing)
|
||||
LtsPictureEditing::LtsPictureEditing(QWidget* parent)
|
||||
: QMainWindow(parent), m_gvPicture(nullptr), m_ui(new Ui::PictureEditing)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
connect(m_ui->actionOpen, &QAction::triggered, this, &LtsPictureEditing::onOpenImage);
|
||||
connect(m_ui->actionSave, &QAction::triggered, this, &LtsPictureEditing::onSavePicture);
|
||||
connect(m_ui->actionQuit, &QAction::triggered, this, &LtsPictureEditing::close);
|
||||
connect(m_ui->pbSetSize, &QPushButton::clicked, this, &LtsPictureEditing::onSetSize);
|
||||
m_ui->setupUi(this);
|
||||
connect(m_ui->actionOpen, &QAction::triggered, this, &LtsPictureEditing::onOpenImage);
|
||||
connect(m_ui->actionSave, &QAction::triggered, this, &LtsPictureEditing::onSavePicture);
|
||||
connect(m_ui->actionQuit, &QAction::triggered, this, &LtsPictureEditing::close);
|
||||
connect(m_ui->pbSetSize, &QPushButton::clicked, this, &LtsPictureEditing::onSetSize);
|
||||
|
||||
connect(m_ui->sbHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
|
||||
connect(m_ui->sbWidth, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
|
||||
connect(m_ui->chbRatio, &QPushButton::clicked, this, &LtsPictureEditing::onRatioClicked);
|
||||
connect(m_ui->sbHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
|
||||
connect(m_ui->sbWidth, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRatioChanged);
|
||||
connect(m_ui->chbRatio, &QPushButton::clicked, this, &LtsPictureEditing::onRatioClicked);
|
||||
|
||||
connect(m_ui->sbXMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onLeftChanged);
|
||||
connect(m_ui->sbXMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRightChanged);
|
||||
connect(m_ui->sbYMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onTopChanged);
|
||||
connect(m_ui->sbYMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onBottomChanged);
|
||||
connect(m_ui->sbXMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onLeftChanged);
|
||||
connect(m_ui->sbXMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onRightChanged);
|
||||
connect(m_ui->sbYMin, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onTopChanged);
|
||||
connect(m_ui->sbYMax, QOverload<int>::of(&QSpinBox::valueChanged), this, &LtsPictureEditing::onBottomChanged);
|
||||
|
||||
addViewToFrame();
|
||||
addViewToFrame();
|
||||
|
||||
connect(this, &LtsPictureEditing::leftChanged, m_gvPicture, &LtsWidgets::LtsPictureView::leftChanged);
|
||||
connect(this, &LtsPictureEditing::rightChanged, m_gvPicture, &LtsWidgets::LtsPictureView::rightChanged);
|
||||
connect(this, &LtsPictureEditing::topChanged, m_gvPicture, &LtsWidgets::LtsPictureView::topChanged);
|
||||
connect(this, &LtsPictureEditing::bottomChanged, m_gvPicture, &LtsWidgets::LtsPictureView::bottomChanged);
|
||||
connect(this, &LtsPictureEditing::leftChanged, m_gvPicture, &LtsWidgets::LtsPictureView::leftChanged);
|
||||
connect(this, &LtsPictureEditing::rightChanged, m_gvPicture, &LtsWidgets::LtsPictureView::rightChanged);
|
||||
connect(this, &LtsPictureEditing::topChanged, m_gvPicture, &LtsWidgets::LtsPictureView::topChanged);
|
||||
connect(this, &LtsPictureEditing::bottomChanged, m_gvPicture, &LtsWidgets::LtsPictureView::bottomChanged);
|
||||
|
||||
connect(this, &LtsPictureEditing::setAspectRatio, m_gvPicture, &LtsWidgets::LtsPictureView::setAspectRatio);
|
||||
connect(this, &LtsPictureEditing::ratioClicked, m_gvPicture, &LtsWidgets::LtsPictureView::ratioClicked);
|
||||
connect(this, &LtsPictureEditing::setAspectRatio, m_gvPicture, &LtsWidgets::LtsPictureView::setAspectRatio);
|
||||
connect(this, &LtsPictureEditing::ratioClicked, m_gvPicture, &LtsWidgets::LtsPictureView::ratioClicked);
|
||||
|
||||
connect(m_gvPicture, &LtsWidgets::LtsPictureView::mouseMoved, this, &LtsPictureEditing::setSpinboxValues);
|
||||
connect(m_gvPicture, &LtsWidgets::LtsPictureView::setLimits, this, &LtsPictureEditing::setSpinboxLimits);
|
||||
connect(this, &LtsPictureEditing::setPicture, m_gvPicture, &LtsWidgets::LtsPictureView::setPicture);
|
||||
connect(m_gvPicture, &LtsWidgets::LtsPictureView::mouseMoved, this, &LtsPictureEditing::setSpinboxValues);
|
||||
connect(m_gvPicture, &LtsWidgets::LtsPictureView::setLimits, this, &LtsPictureEditing::setSpinboxLimits);
|
||||
connect(this, &LtsPictureEditing::setPicture, m_gvPicture, &LtsWidgets::LtsPictureView::setPicture);
|
||||
|
||||
onRatioChanged();
|
||||
onRatioChanged();
|
||||
}
|
||||
|
||||
LtsPictureEditing::~LtsPictureEditing()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void LtsPictureEditing::addViewToFrame()
|
||||
{
|
||||
QHBoxLayout *layout(new QHBoxLayout(m_ui->frPicFrame));
|
||||
m_gvPicture = new LtsWidgets::LtsPictureView(m_ui->frPicFrame);
|
||||
layout->addWidget(m_gvPicture);
|
||||
m_gvPicture->setEnabled(false);
|
||||
QHBoxLayout* layout(new QHBoxLayout(m_ui->frPicFrame));
|
||||
m_gvPicture = new LtsWidgets::LtsPictureView(m_ui->frPicFrame);
|
||||
layout->addWidget(m_gvPicture);
|
||||
m_gvPicture->setEnabled(false);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onOpenImage()
|
||||
{
|
||||
const QStringList filter ({
|
||||
tr("Images (*.jpg *.jpeg *.png)")
|
||||
});
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"),
|
||||
QStringLiteral("../picture_editing"),
|
||||
filter.join(QStringLiteral(";;")));
|
||||
const QStringList filter({tr("Images (*.jpg *.jpeg *.png)")});
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QStringLiteral("../picture_editing"),
|
||||
filter.join(QStringLiteral(";;")));
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo fi(fileName);
|
||||
if (!fi.isReadable())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while loading the file.\n"
|
||||
"The loaded file is not readable."));
|
||||
return;
|
||||
}
|
||||
QFileInfo fi(fileName);
|
||||
if (!fi.isReadable())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"),
|
||||
tr("An error occurred while loading the file.\n"
|
||||
"The loaded file is not readable."));
|
||||
return;
|
||||
}
|
||||
|
||||
QImage pic;
|
||||
pic.load(fileName);
|
||||
if (pic.isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while loading the file.\n"
|
||||
"The loaded file is no picture file.\n"
|
||||
"Please load *.jpg, *.jpeg, *.png files only."));
|
||||
return;
|
||||
}
|
||||
m_image = pic;
|
||||
emit setPicture(pic, QPoint(0, 0), true);
|
||||
m_gvPicture->setEnabled(true);
|
||||
m_gvPicture->newRubberBand();
|
||||
QImage pic;
|
||||
pic.load(fileName);
|
||||
if (pic.isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"),
|
||||
tr("An error occurred while loading the file.\n"
|
||||
"The loaded file is no picture file.\n"
|
||||
"Please load *.jpg, *.jpeg, *.png files only."));
|
||||
return;
|
||||
}
|
||||
m_image = pic;
|
||||
emit setPicture(pic, QPoint(0, 0), true);
|
||||
m_gvPicture->setEnabled(true);
|
||||
m_gvPicture->newRubberBand();
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onSetSize()
|
||||
{
|
||||
if (m_image.isNull())
|
||||
return;
|
||||
if (m_image.isNull())
|
||||
return;
|
||||
|
||||
m_gvPicture->hideRubberband();
|
||||
m_gvPicture->hideRubberband();
|
||||
|
||||
int xMin = m_ui->sbXMin->value() - 1;
|
||||
int yMin = m_ui->sbYMin->value() - 1;
|
||||
int xMax = m_ui->sbXMax->value() - 1;
|
||||
int yMax = m_ui->sbYMax->value() - 1;
|
||||
int xMin = m_ui->sbXMin->value() - 1;
|
||||
int yMin = m_ui->sbYMin->value() - 1;
|
||||
int xMax = m_ui->sbXMax->value() - 1;
|
||||
int yMax = m_ui->sbYMax->value() - 1;
|
||||
|
||||
if (xMax < xMin || yMax < yMin || xMax == xMin || yMax == yMin)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
if (xMax < xMin || yMax < yMin || xMax == xMin || yMax == yMin)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
QRect picRect(xMin,
|
||||
yMin,
|
||||
xMax - xMin,
|
||||
yMax - yMin);
|
||||
QImage newPic = m_image.copy(picRect);
|
||||
emit setPicture(newPic, QPoint(xMin, yMin), false);
|
||||
QRect picRect(xMin, yMin, xMax - xMin, yMax - yMin);
|
||||
QImage newPic = m_image.copy(picRect);
|
||||
emit setPicture(newPic, QPoint(xMin, yMin), false);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onSavePicture()
|
||||
{
|
||||
if (m_gvPicture->getImage()->pixmap().isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while saving the picture\n"
|
||||
"Please load a picture before saving it."));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Open Image"), QLatin1String("../picture_editing"),
|
||||
tr("Images (*.jpg *.jpeg *.png)"));
|
||||
if (filename.isEmpty())
|
||||
if (m_gvPicture->getImage()->pixmap().isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"), tr("An error occurred while saving the picture.\n"
|
||||
"Please choose a valid path to save the picture."));
|
||||
return;
|
||||
QMessageBox::warning(this, tr("Error!"),
|
||||
tr("An error occurred while saving the picture\n"
|
||||
"Please load a picture before saving it."));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Open Image"), QLatin1String("../picture_editing"),
|
||||
tr("Images (*.jpg *.jpeg *.png)"));
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error!"),
|
||||
tr("An error occurred while saving the picture.\n"
|
||||
"Please choose a valid path to save the picture."));
|
||||
return;
|
||||
}
|
||||
|
||||
m_gvPicture->getImage()->pixmap().save(filename, "PNG");
|
||||
}
|
||||
m_gvPicture->getImage()->pixmap().save(filename, "PNG");
|
||||
}
|
||||
}
|
||||
|
||||
void LtsPictureEditing::setSpinboxLimits(const QSize &picSize, bool setValues)
|
||||
void LtsPictureEditing::setSpinboxLimits(const QSize& picSize, bool setValues)
|
||||
{
|
||||
m_ui->sbXMin->setMaximum(picSize.width());
|
||||
m_ui->sbXMax->setMaximum(picSize.width());
|
||||
m_ui->sbYMin->setMaximum(picSize.height());
|
||||
m_ui->sbYMax->setMaximum(picSize.height());
|
||||
m_ui->sbXMin->setMaximum(picSize.width());
|
||||
m_ui->sbXMax->setMaximum(picSize.width());
|
||||
m_ui->sbYMin->setMaximum(picSize.height());
|
||||
m_ui->sbYMax->setMaximum(picSize.height());
|
||||
|
||||
if (setValues)
|
||||
{
|
||||
m_ui->sbXMin->setValue(0);
|
||||
m_ui->sbYMin->setValue(0);
|
||||
m_ui->sbXMax->setValue(picSize.width() - 1);
|
||||
m_ui->sbYMax->setValue(picSize.height() - 1);
|
||||
}
|
||||
if (setValues)
|
||||
{
|
||||
m_ui->sbXMin->setValue(0);
|
||||
m_ui->sbYMin->setValue(0);
|
||||
m_ui->sbXMax->setValue(picSize.width() - 1);
|
||||
m_ui->sbYMax->setValue(picSize.height() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsPictureEditing::setSpinboxValues(const QRect &picRect)
|
||||
void LtsPictureEditing::setSpinboxValues(const QRect& picRect)
|
||||
{
|
||||
m_ui->sbXMin->setValue(picRect.left());
|
||||
m_ui->sbYMin->setValue(picRect.top());
|
||||
m_ui->sbXMax->setValue(picRect.right());
|
||||
m_ui->sbYMax->setValue(picRect.bottom());
|
||||
m_ui->sbXMin->setValue(picRect.left());
|
||||
m_ui->sbYMin->setValue(picRect.top());
|
||||
m_ui->sbXMax->setValue(picRect.right());
|
||||
m_ui->sbYMax->setValue(picRect.bottom());
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onRatioChanged()
|
||||
{
|
||||
double ratio = double(m_ui->sbWidth->value()) / double(m_ui->sbHeight->value());
|
||||
emit setAspectRatio(ratio);
|
||||
double ratio = double(m_ui->sbWidth->value()) / double(m_ui->sbHeight->value());
|
||||
emit setAspectRatio(ratio);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onRatioClicked()
|
||||
{
|
||||
if (m_ui->chbRatio->isChecked())
|
||||
{
|
||||
m_ui->sbHeight->setEnabled(true);
|
||||
m_ui->sbWidth->setEnabled(true);
|
||||
emit ratioClicked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->sbHeight->setEnabled(false);
|
||||
m_ui->sbWidth->setEnabled(false);
|
||||
emit ratioClicked(false);
|
||||
}
|
||||
if (m_ui->chbRatio->isChecked())
|
||||
{
|
||||
m_ui->sbHeight->setEnabled(true);
|
||||
m_ui->sbWidth->setEnabled(true);
|
||||
emit ratioClicked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->sbHeight->setEnabled(false);
|
||||
m_ui->sbWidth->setEnabled(false);
|
||||
emit ratioClicked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onLeftChanged(int left)
|
||||
{
|
||||
emit leftChanged(left);
|
||||
emit leftChanged(left);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onRightChanged(int right)
|
||||
{
|
||||
emit rightChanged(right);
|
||||
emit rightChanged(right);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onTopChanged(int top)
|
||||
{
|
||||
emit topChanged(top);
|
||||
emit topChanged(top);
|
||||
}
|
||||
|
||||
void LtsPictureEditing::onBottomChanged(int bottom)
|
||||
{
|
||||
emit bottomChanged(bottom);
|
||||
emit bottomChanged(bottom);
|
||||
}
|
||||
|
||||
|
||||
void LtsPictureEditing::clear()
|
||||
{
|
||||
emit setPicture(QImage(), QPoint(), false);
|
||||
emit setPicture(QImage(), QPoint(), false);
|
||||
}
|
||||
Executable → Regular
+37
-39
@@ -1,61 +1,59 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QObject>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class PictureEditing;
|
||||
}
|
||||
|
||||
namespace LtsWidgets{
|
||||
class LtsPictureView;
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsPictureView;
|
||||
}
|
||||
|
||||
|
||||
class LtsPictureEditing : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsPictureEditing(QWidget *parent = nullptr);
|
||||
~LtsPictureEditing();
|
||||
public:
|
||||
explicit LtsPictureEditing(QWidget* parent = nullptr);
|
||||
~LtsPictureEditing();
|
||||
|
||||
private:
|
||||
QImage m_grayImage;
|
||||
QImage m_image;
|
||||
private:
|
||||
QImage m_grayImage;
|
||||
QImage m_image;
|
||||
|
||||
LtsWidgets::LtsPictureView *m_gvPicture;
|
||||
LtsWidgets::LtsPictureView* m_gvPicture;
|
||||
|
||||
Ui::PictureEditing *m_ui;
|
||||
Ui::PictureEditing* m_ui;
|
||||
|
||||
private:
|
||||
void setSpinboxLimits(const QSize &picSize, bool setValues = true);
|
||||
void clear();
|
||||
void addViewToFrame();
|
||||
void initRatio();
|
||||
private:
|
||||
void setSpinboxLimits(const QSize& picSize, bool setValues = true);
|
||||
void clear();
|
||||
void addViewToFrame();
|
||||
void initRatio();
|
||||
|
||||
private slots:
|
||||
void onOpenImage();
|
||||
void onSetSize();
|
||||
void setSpinboxValues(const QRect &picRect);
|
||||
void onRatioChanged();
|
||||
void onRatioClicked();
|
||||
void onSavePicture();
|
||||
void onLeftChanged(int left);
|
||||
void onRightChanged(int right);
|
||||
void onTopChanged(int top);
|
||||
void onBottomChanged(int bottom);
|
||||
private slots:
|
||||
void onOpenImage();
|
||||
void onSetSize();
|
||||
void setSpinboxValues(const QRect& picRect);
|
||||
void onRatioChanged();
|
||||
void onRatioClicked();
|
||||
void onSavePicture();
|
||||
void onLeftChanged(int left);
|
||||
void onRightChanged(int right);
|
||||
void onTopChanged(int top);
|
||||
void onBottomChanged(int bottom);
|
||||
|
||||
signals:
|
||||
void setPicture(const QImage &, const QPoint &, const bool flag);
|
||||
void setAspectRatio(double ratio);
|
||||
void ratioClicked(bool enabled);
|
||||
int leftChanged(int left);
|
||||
int rightChanged(int right);
|
||||
int topChanged(int top);
|
||||
int bottomChanged(int bottom);
|
||||
signals:
|
||||
void setPicture(const QImage&, const QPoint&, const bool flag);
|
||||
void setAspectRatio(double ratio);
|
||||
void ratioClicked(bool enabled);
|
||||
int leftChanged(int left);
|
||||
int rightChanged(int right);
|
||||
int topChanged(int top);
|
||||
int bottomChanged(int bottom);
|
||||
};
|
||||
Executable → Regular
+26
-27
@@ -1,39 +1,38 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_picture_editing.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <iostream>
|
||||
|
||||
static void qtMsgHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
|
||||
static void qtMsgHandler(QtMsgType type, const QMessageLogContext&, const QString& msg)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
std::cout << "DEBUG: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
std::cout << "INFO: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
std::cout << "WARN: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
std::cerr << "ERROR: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
std::cerr << "FATAL: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
std::cout << "DEBUG: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
std::cout << "INFO: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
std::cout << "WARN: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
std::cerr << "ERROR: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
std::cerr << "FATAL: " << qPrintable(msg) << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
LtsPictureEditing w;
|
||||
w.show();
|
||||
QApplication a(argc, argv);
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
LtsPictureEditing w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
return a.exec();
|
||||
}
|
||||
Executable → Regular
+9
-25
@@ -1,31 +1,15 @@
|
||||
#include "window.h"
|
||||
|
||||
#include <LtsWidgets/lts_date_time_edit.h>
|
||||
#include <QApplication>
|
||||
|
||||
#include "window.h"
|
||||
#include <LtsWidgets/lts_date_time_edit.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QApplication app(argc, argv);
|
||||
|
||||
LtsWidgets::LtsDateTimeEdit dte;
|
||||
dte.activateWindow();
|
||||
dte.show();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsWidgets::LtsDateTimeEdit dte;
|
||||
dte.activateWindow();
|
||||
dte.show();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return app.exec();
|
||||
return app.exec();
|
||||
}
|
||||
Executable → Regular
+26
-37
@@ -1,59 +1,48 @@
|
||||
#include "window.h"
|
||||
|
||||
#include <LtsWidgets/lts_notification_box.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
Window::Window(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
Window::Window(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
|
||||
|
||||
setGeometry(x(), y(), 300, 300);
|
||||
setGeometry(x(), y(), 300, 300);
|
||||
|
||||
QHBoxLayout *lay = new QHBoxLayout;
|
||||
QHBoxLayout* lay = new QHBoxLayout;
|
||||
|
||||
lay->setMargin(0);
|
||||
|
||||
lay->setMargin(0);
|
||||
|
||||
auto x1 = new LtsWidgets::LtsNotificationBox;
|
||||
lay->addWidget(x1);
|
||||
|
||||
auto x1 = new LtsWidgets::LtsNotificationBox;
|
||||
lay->addWidget(x1);
|
||||
if (qApp->arguments().count() < 2)
|
||||
abort();
|
||||
|
||||
LtsNotificationBox::MessageType type;
|
||||
|
||||
if (qApp->arguments().count() < 2)
|
||||
abort();
|
||||
if (qApp->arguments().at(1) == QStringLiteral("e"))
|
||||
type = LtsNotificationBox::MessageType::Error;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("w"))
|
||||
type = LtsNotificationBox::MessageType::Warning;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("i"))
|
||||
type = LtsNotificationBox::MessageType::Info;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("s"))
|
||||
type = LtsNotificationBox::MessageType::Success;
|
||||
else
|
||||
abort();
|
||||
|
||||
x1->message(QStringLiteral("Title Message"),
|
||||
QStringLiteral("A text that consists of a lot of characters and also even has<br />two lines."), type);
|
||||
connect(x1, &LtsNotificationBox::signalClose, this, &QWidget::close);
|
||||
|
||||
LtsNotificationBox::MessageType type;
|
||||
setLayout(lay);
|
||||
|
||||
if (qApp->arguments().at(1) == QStringLiteral("e"))
|
||||
type = LtsNotificationBox::MessageType::Error;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("w"))
|
||||
type = LtsNotificationBox::MessageType::Warning;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("i"))
|
||||
type = LtsNotificationBox::MessageType::Info;
|
||||
else if (qApp->arguments().at(1) == QStringLiteral("s"))
|
||||
type = LtsNotificationBox::MessageType::Success;
|
||||
else
|
||||
abort();
|
||||
|
||||
x1->message(QStringLiteral("Title Message"), QStringLiteral("A text that consists of a lot of characters and also even has<br />two lines."), type);
|
||||
connect(x1, &LtsNotificationBox::signalClose, this, &QWidget::close);
|
||||
|
||||
setLayout(lay);
|
||||
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
||||
Window::~Window() {}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Executable → Regular
+5
-8
@@ -1,17 +1,14 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Window(QWidget *parent = nullptr);
|
||||
~Window();
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
Window(QWidget* parent = nullptr);
|
||||
~Window();
|
||||
};
|
||||
}
|
||||
} // namespace LtsWidgets
|
||||
Reference in new issue
Block a user