Client app template and ui

This commit is contained in:
pokamest 2020-11-23 16:20:25 +03:00
parent 3006c67472
commit f68415f08e
53 changed files with 4280 additions and 0 deletions

View file

@ -0,0 +1,193 @@
#include "SlidingStackedWidget.h"
SlidingStackedWidget::SlidingStackedWidget(QWidget *parent)
: QStackedWidget(parent)
{
if (parent != 0) {
m_mainwindow = parent;
}
else {
m_mainwindow = this;
qDebug().noquote() << "ATTENTION: untested mainwindow case !";
}
// parent should not be 0; not tested for any other case yet !!
#ifdef Q_OS_SYMBIAN
#ifndef __S60_50__
qDebug().noquote() << "WARNING: ONLY TESTED AND 5TH EDITION";
#endif // __S60_50__
#endif // Q_OS_SYMBIAN
// Now, initialize some private variables with default values
m_vertical = false;
// setVerticalMode(true);
m_speed = 500;
m_animationtype = QEasingCurve::OutBack; // check out the QEasingCurve documentation for different styles
m_now = 0;
m_next = 0;
m_wrap = false;
m_pnow = QPoint(0,0);
m_active = false;
}
SlidingStackedWidget::~SlidingStackedWidget() {
}
void SlidingStackedWidget::setVerticalMode(bool vertical) {
m_vertical = vertical;
}
void SlidingStackedWidget::setSpeed(int speed) {
m_speed = speed;
}
void SlidingStackedWidget::setAnimation(enum QEasingCurve::Type animationtype) {
m_animationtype = animationtype;
}
void SlidingStackedWidget::setWrap(bool wrap) {
m_wrap = wrap;
}
void SlidingStackedWidget::slideInNext() {
int now = currentIndex();
if (m_wrap || (now < count() - 1))
// count is inherit from QStackedWidget
slideInIdx(now + 1);
}
void SlidingStackedWidget::slideInPrev() {
int now = currentIndex();
if (m_wrap || (now > 0))
slideInIdx(now - 1);
}
void SlidingStackedWidget::slideInIdx(int idx, enum t_direction direction) {
// int idx, t_direction direction=AUTOMATIC
if (idx > count() - 1) {
direction = m_vertical ? TOP2BOTTOM : RIGHT2LEFT;
idx = (idx) % count();
}
else if (idx < 0) {
direction = m_vertical ? BOTTOM2TOP: LEFT2RIGHT;
idx = (idx + count()) % count();
}
slideInWgtImpl(widget(idx), direction);
// widget() is a function inherited from QStackedWidget
}
void SlidingStackedWidget::slideInWidget(QWidget *widget, SlidingStackedWidget::t_direction direction)
{
Q_UNUSED(direction);
#ifdef Q_OS_WIN
int idx = indexOf(widget);
slideInIdx(idx, direction);
#endif
#ifdef Q_OS_MAC
setCurrentWidget(widget);
#endif
}
void SlidingStackedWidget::slideInWgtImpl(QWidget * newwidget, enum t_direction direction) {
if (m_active) {
return;
}
else m_active = true;
enum t_direction directionhint;
int now = currentIndex(); // currentIndex() is a function inherited from QStackedWidget
int next = indexOf(newwidget);
if (now == next) {
m_active = false;
return;
}
else if (now < next) {
directionhint = m_vertical ? TOP2BOTTOM : RIGHT2LEFT;
}
else {
directionhint = m_vertical ? BOTTOM2TOP : LEFT2RIGHT;
}
if (direction == AUTOMATIC) {
direction = directionhint;
}
// NOW....
// calculate the shifts
int offsetx = frameRect().width(); // inherited from mother
int offsety = frameRect().height(); // inherited from mother
// the following is important, to ensure that the new widget
// has correct geometry information when sliding in first time
widget(next)->setGeometry(0, 0, offsetx, offsety);
if (direction == BOTTOM2TOP) {
offsetx = 0;
offsety = -offsety;
}
else if (direction == TOP2BOTTOM) {
offsetx = 0;
// offsety = offsety;
}
else if (direction == RIGHT2LEFT) {
offsetx = -offsetx;
offsety = 0;
}
else if (direction == LEFT2RIGHT) {
// offsetx = offsetx;
offsety = 0;
}
// re-position the next widget outside/aside of the display area
QPoint pnext = widget(next)->pos();
QPoint pnow = widget(now)->pos();
m_pnow = pnow;
widget(next)->move(pnext.x() - offsetx, pnext.y() - offsety);
// make it visible/show
widget(next)->show();
widget(next)->raise();
// animate both, the now and next widget to the side, using animation framework
QPropertyAnimation *animnow = new QPropertyAnimation(widget(now), "pos");
animnow->setDuration(m_speed);
animnow->setEasingCurve(m_animationtype);
animnow->setStartValue(QPoint(pnow.x(), pnow.y()));
animnow->setEndValue(QPoint(offsetx + pnow.x(), offsety + pnow.y()));
QPropertyAnimation *animnext = new QPropertyAnimation(widget(next), "pos");
animnext->setDuration(m_speed);
animnext->setEasingCurve(m_animationtype);
animnext->setStartValue(QPoint(-offsetx + pnext.x(), offsety + pnext.y()));
animnext->setEndValue(QPoint(pnext.x(), pnext.y()));
QParallelAnimationGroup *animgroup = new QParallelAnimationGroup;
animgroup->addAnimation(animnow);
animgroup->addAnimation(animnext);
QObject::connect(animgroup, SIGNAL(finished()),this,SLOT(animationDoneSlot()));
m_next = next;
m_now = now;
m_active = true;
animgroup->start();
// note; the rest is done via a connect from the animation ready;
// animation->finished() provides a signal when animation is done;
// so we connect this to some post processing slot,
// that we implement here below in animationDoneSlot.
}
void SlidingStackedWidget::animationDoneSlot(void) {
// when ready, call the QStackedWidget slot setCurrentIndex(int)
setCurrentIndex(m_next); // this function is inherited from QStackedWidget
// then hide the outshifted widget now, and (may be done already implicitely by QStackedWidget)
widget(m_now)->hide();
// then set the position of the outshifted widget now back to its original
widget(m_now)->move(m_pnow);
// so that the application could also still call the QStackedWidget original functions/slots for changings
// widget(m_now)->update();
// setCurrentIndex(m_next); // this function is inherit from QStackedWidget
m_active = false;
emit animationFinished();
}

View file

@ -0,0 +1,76 @@
#ifndef SLIDINGSTACKEDWIDGET_H
#define SLIDINGSTACKEDWIDGET_H
#include <QStackedWidget>
#include <QWidget>
#include <QDebug>
#include <QEasingCurve>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
/* Description
SlidingStackedWidget is a class that is derived from QtStackedWidget
and allows smooth side shifting of widgets, in addition
to the original hard switching from one to another as offered by
QStackedWidget itself.
*/
class SlidingStackedWidget : public QStackedWidget {
Q_OBJECT
public:
// This enumeration is used to define the animation direction
enum t_direction {
LEFT2RIGHT,
RIGHT2LEFT,
TOP2BOTTOM,
BOTTOM2TOP,
AUTOMATIC
};
// The Constructor and Destructor
SlidingStackedWidget(QWidget *parent);
~SlidingStackedWidget(void);
public slots:
// Some basic settings API
void setSpeed(int speed); // animation duration in milliseconds
void setAnimation(enum QEasingCurve::Type animationtype); // check out the QEasingCurve documentation for different styles
void setVerticalMode(bool vertical=true);
void setWrap(bool wrap); // wrapping is related to slideInNext/Prev;it defines the behaviour when reaching last/first page
// The Animation / Page Change API
void slideInNext();
void slideInPrev();
void slideInIdx(int idx, enum t_direction direction = AUTOMATIC);
void slideInWidget(QWidget *widget, enum t_direction direction = AUTOMATIC);
signals:
// this is used for internal purposes in the class engine
void animationFinished(void);
protected slots:
// this is used for internal purposes in the class engine
void animationDoneSlot(void);
protected:
// this is used for internal purposes in the class engine
void slideInWgtImpl(QWidget *widget, enum t_direction direction = AUTOMATIC);
QWidget *m_mainwindow;
int m_speed;
enum QEasingCurve::Type m_animationtype;
bool m_vertical;
int m_now;
int m_next;
bool m_wrap;
QPoint m_pnow;
bool m_active;
QList<QWidget*> blockedPageList;
};
#endif // SLIDINGSTACKEDWIDGET_H

View file

@ -0,0 +1,76 @@
#include "customshadoweffect.h"
#include <QPainter>
CustomShadowEffect::CustomShadowEffect(QObject *parent) :
QGraphicsEffect(parent),
_distance(4.0f),
_blurRadius(10.0f),
_color(0, 0, 0, 80)
{
}
QT_BEGIN_NAMESPACE
extern Q_WIDGETS_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0 );
QT_END_NAMESPACE
void CustomShadowEffect::draw(QPainter* painter)
{
// if nothing to show outside the item, just draw source
if ((blurRadius() + distance()) <= 0) {
drawSource(painter);
return;
}
PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect;
QPoint offset;
const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
// return if no source
if (px.isNull())
return;
// save world transform
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
// Calculate size for the background image
QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance());
QImage tmp(szi, QImage::Format_ARGB32_Premultiplied);
QPixmap scaled = px.scaled(szi);
tmp.fill(0);
QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled);
tmpPainter.end();
// blur the alpha channel
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
blurred.fill(0);
QPainter blurPainter(&blurred);
qt_blurImage(&blurPainter, tmp, blurRadius(), false, true);
blurPainter.end();
tmp = blurred;
// blacken the image...
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color());
tmpPainter.end();
// draw the blurred shadow...
painter->drawImage(offset, tmp);
// draw the actual pixmap...
painter->drawPixmap(offset, px, QRectF());
// restore world transform
painter->setWorldTransform(restoreTransform);
}
QRectF CustomShadowEffect::boundingRectFor(const QRectF& rect) const
{
qreal delta = blurRadius() + distance();
return rect.united(rect.adjusted(-delta, -delta, delta, delta));
}

View file

@ -0,0 +1,31 @@
#ifndef CUSTOMSHADOWEFFECT_H
#define CUSTOMSHADOWEFFECT_H
#include <QGraphicsDropShadowEffect>
#include <QGraphicsEffect>
class CustomShadowEffect : public QGraphicsEffect
{
Q_OBJECT
public:
explicit CustomShadowEffect(QObject *parent = 0);
void draw(QPainter* painter);
QRectF boundingRectFor(const QRectF& rect) const;
inline void setDistance(qreal distance) { _distance = distance; updateBoundingRect(); }
inline qreal distance() const { return _distance; }
inline void setBlurRadius(qreal blurRadius) { _blurRadius = blurRadius; updateBoundingRect(); }
inline qreal blurRadius() const { return _blurRadius; }
inline void setColor(const QColor& color) { _color = color; }
inline QColor color() const { return _color; }
private:
qreal _distance;
qreal _blurRadius;
QColor _color;
};
#endif // CUSTOMSHADOWEFFECT_H

36
client/ui/mainwindow.cpp Normal file
View file

@ -0,0 +1,36 @@
#include <QMetaEnum>
#include <QMovie>
#include <QMessageBox>
#include <QMouseEvent>
#include <QScroller>
#include <QScrollBar>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QGridLayout>
#include <QTime>
#include "mainwindow.h"
#ifdef Q_OS_WIN
#include "ui_mainwindow.h"
#endif
#ifdef Q_OS_MAC
#include "ui_mainwindow_mac.h"
#include "publib/macos_functions.h"
#endif
MainWindow::MainWindow(bool useForceUseBrightIcons, QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow),
forceUseBrightIcons(useForceUseBrightIcons)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}

43
client/ui/mainwindow.h Normal file
View file

@ -0,0 +1,43 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QJsonDocument>
#include <QClipboard>
#include <QStringListModel>
#include <QDataStream>
#include <QGraphicsBlurEffect>
#include "customshadoweffect.h"
namespace Ui {
class MainWindow;
}
/**
* @brief The MainWindow class - Main application window
*/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(bool setForceUseBrightIcons = false, QWidget *parent = nullptr);
~MainWindow();
public slots:
private slots:
private:
Ui::MainWindow *ui;
bool forceUseBrightIcons = false;
};
#endif // MAINWINDOW_H

1293
client/ui/mainwindow.ui Normal file

File diff suppressed because it is too large Load diff

1665
client/ui/mainwindow_mac.ui Normal file

File diff suppressed because it is too large Load diff