233 lines
6.6 KiB
C++
233 lines
6.6 KiB
C++
|
|
|
|
#pragma once
|
|
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <LtsUtilsCore/lts_translatable_identifier.h>
|
|
#include <QAbstractItemView>
|
|
#include <QIcon>
|
|
#include <QScrollArea>
|
|
#include <QScroller>
|
|
#include <QString>
|
|
#include <functional>
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
class LtsDialog;
|
|
|
|
inline QString readableDuration(qint64 msecs, bool foldDays = true)
|
|
{
|
|
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));
|
|
|
|
qint64 secs = msecs / 1000;
|
|
qint64 mins = secs / 60;
|
|
qint64 hours = mins / 60;
|
|
qint64 days = hours / 24;
|
|
|
|
if (foldDays)
|
|
days = 0;
|
|
else
|
|
hours = hours % 24;
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
return retVal;
|
|
}
|
|
|
|
inline void addTouchScroll(QWidget* widget)
|
|
{
|
|
if (!widget)
|
|
return;
|
|
widget->setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
enum class ButtonSize {
|
|
eDefault = 40,
|
|
|
|
};
|
|
|
|
enum class ButtonStyle { eAll = 1, eTextOnly, eIconOnly, eTextNextToIcon };
|
|
|
|
enum class LayoutArea {
|
|
eUnknown,
|
|
eInfoTab,
|
|
eDialogTab,
|
|
eSpecialTab,
|
|
eMainTab,
|
|
};
|
|
|
|
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,
|
|
eTerminated = 1 << 5,
|
|
|
|
eAll = eCreated | eStarted | ePaused | eStopped | eTerminated
|
|
};
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<State>)
|
|
} // namespace ExerciseState
|
|
|
|
typedef ExerciseState::State ExcState;
|
|
typedef QFlags<ExcState> ExerciseStates;
|
|
|
|
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;
|
|
|
|
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)
|
|
{
|
|
}
|
|
|
|
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_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)
|
|
};
|
|
|
|
} // namespace LtsWidgets
|
|
Q_DECLARE_METATYPE(LtsWidgets::Designer::ButtonSize)
|
|
Q_DECLARE_METATYPE(LtsWidgets::Designer::ButtonStyle)
|
|
Q_DECLARE_METATYPE(LtsWidgets::Designer::LayoutArea)
|
|
|
|
Q_DECLARE_METATYPE(LtsWidgets::ButtonSize)
|
|
Q_DECLARE_METATYPE(LtsWidgets::ButtonStyle)
|
|
Q_DECLARE_METATYPE(LtsWidgets::LayoutArea)
|