Initial commit of BudgetPro
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include "arrowrectangle.h"
|
||||
|
||||
#include <DApplication>
|
||||
|
||||
ArrowRectangle::ArrowRectangle(ArrowDirection direction, QWidget *parent)
|
||||
: DArrowRectangle(direction, DArrowRectangle::FloatWindow, parent)
|
||||
{
|
||||
connect(qApp, &DApplication::focusChanged, this, [=](QWidget* old, QWidget* now){
|
||||
Q_UNUSED(old);
|
||||
if (now != this && !this->isAncestorOf(now))
|
||||
{
|
||||
hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ArrowRectangle::hideEvent(QHideEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
emit hideWindow();
|
||||
}
|
||||
|
||||
ArrowRectangle::~ArrowRectangle()
|
||||
{}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef ARROWRECTANGLE_H
|
||||
#define ARROWRECTANGLE_H
|
||||
|
||||
#include <QHideEvent>
|
||||
|
||||
#include <darrowrectangle.h>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
class ArrowRectangle : public DArrowRectangle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArrowRectangle(ArrowDirection direction, QWidget * parent = 0);
|
||||
~ArrowRectangle();
|
||||
|
||||
signals:
|
||||
void hideWindow();
|
||||
|
||||
protected:
|
||||
void hideEvent(QHideEvent* e);
|
||||
};
|
||||
|
||||
#endif // ARROWRECTANGLE_H
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* kirigaya <kirigaya@mkacg.com>
|
||||
* Hualet <mr.asianwang@gmail.com>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
* kirigaya <kirigaya@mkacg.com>
|
||||
* Hualet <mr.asianwang@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "avatarwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
#include <QRect>
|
||||
#include <QColor>
|
||||
#include <QPainterPath>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
AvatarWidget::AvatarWidget(QWidget *parent)
|
||||
: QLabel(parent),
|
||||
m_hover(false),
|
||||
m_deleable(false),
|
||||
m_selected(false),
|
||||
m_arrowed(false)
|
||||
{
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
//mainLayout->setMargin(0);
|
||||
mainLayout->setSpacing(0);
|
||||
|
||||
setLayout(mainLayout);
|
||||
//setFixedSize(PIX_SIZE, PIX_SIZE);
|
||||
setObjectName("AvatarWidget");
|
||||
}
|
||||
|
||||
AvatarWidget::AvatarWidget(const QString &avatar, QWidget *parent)
|
||||
: AvatarWidget(parent)
|
||||
{
|
||||
setAvatarPath(avatar);
|
||||
}
|
||||
|
||||
void AvatarWidget::setSelected(const bool selected)
|
||||
{
|
||||
m_selected = selected;
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::setDeletable(const bool deletable)
|
||||
{
|
||||
m_deleable = deletable;
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::setArrowed(const bool arrowed)
|
||||
{
|
||||
m_arrowed = arrowed;
|
||||
update();
|
||||
}
|
||||
|
||||
const QString AvatarWidget::avatarPath() const
|
||||
{
|
||||
return m_avatarPath;
|
||||
}
|
||||
|
||||
void AvatarWidget::setAvatarPath(const QString &avatar)
|
||||
{
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
QString avatarPath = avatar;
|
||||
|
||||
/*
|
||||
if (ratio > 1.0)
|
||||
avatarPath.replace("icons/", "icons/bigger/");
|
||||
*/
|
||||
|
||||
QUrl url(avatarPath);
|
||||
if (!QFile(url.toLocalFile()).exists())
|
||||
url = QUrl(avatar);
|
||||
|
||||
m_avatarPath = url.toString();
|
||||
m_avatar = QPixmap(avatar).scaled(size() * ratio, Qt::KeepAspectRatio, Qt::FastTransformation);
|
||||
m_avatar.setDevicePixelRatio(ratio*2);
|
||||
|
||||
setAccessibleName(m_avatarPath);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::setAvatarPixmap(const QPixmap avatar)
|
||||
{
|
||||
m_avatar = avatar;
|
||||
setAccessibleName("");
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (rect().contains(e->pos()))
|
||||
{
|
||||
Q_EMIT clicked(avatarPath());
|
||||
if(e->pos().x() > (rect().width() / 2))
|
||||
{
|
||||
Q_EMIT addClicked(avatarPath());
|
||||
}
|
||||
else
|
||||
{
|
||||
setAvatarPath("");
|
||||
setAccessibleName("");
|
||||
Q_EMIT removeClicked(avatarPath());
|
||||
}
|
||||
}
|
||||
|
||||
QWidget::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
void AvatarWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainterPath painterPath;
|
||||
//painterPath.addEllipse(QRect(0, 0, width(), height()));
|
||||
painterPath.addRoundedRect(QRect(0, 0, width(), height()), 5 ,5 );
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setClipPath(painterPath);
|
||||
|
||||
painter.drawPixmap(e->rect(), m_avatar);
|
||||
|
||||
if (m_selected)
|
||||
{
|
||||
setAccessibleDescription("selectedIcon");
|
||||
QPen pen(Qt::transparent);
|
||||
pen.setWidth(4);
|
||||
pen.setColor(Qt::white);
|
||||
painter.setPen(pen);
|
||||
painter.setBrush(Qt::transparent);
|
||||
painter.drawEllipse(rect());
|
||||
};
|
||||
|
||||
//当鼠标移动到图像上面
|
||||
if (m_hover)
|
||||
{
|
||||
painter.setPen(Qt::NoPen);
|
||||
//宽高
|
||||
int w = this->rect().width();
|
||||
int h = this->rect().height();
|
||||
//矩形
|
||||
QRect rect1(0, h - h / 4, w / 2 - 1, h - h / 4);
|
||||
QRect rect2(w / 2 + 1, h - h / 4, w, h - h / 4);
|
||||
// 反走样
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
// 设置渐变色
|
||||
QLinearGradient linear(QPoint(0, h - h / 4), QPoint(0, h));
|
||||
linear.setColorAt(0, QColor(0, 0, 0, 0.00 * 255));
|
||||
linear.setColorAt(1, QColor(0, 0, 0, 0.50 * 255));
|
||||
|
||||
// 设置显示模式
|
||||
linear.setSpread(QGradient::PadSpread);
|
||||
painter.setBrush(linear);
|
||||
//painter.drawRect(rect1);
|
||||
//painter.drawRect(rect2);
|
||||
|
||||
|
||||
QRadialGradient radialGrad(QPointF(400, 150), 100);
|
||||
radialGrad.setColorAt(0, QColor(0, 0, 0, 0.00 * 255));
|
||||
radialGrad.setColorAt(1, QColor(0, 0, 0, 0.50 * 255));
|
||||
QRect rect_radial(300,50,200,200);
|
||||
painter.fillRect(rect_radial, radialGrad);
|
||||
|
||||
linear.setSpread(QGradient::PadSpread);
|
||||
painter.setBrush(linear);
|
||||
painter.drawEllipse(QRect(0, h - h / 4, 50, h - h / 4));
|
||||
painter.drawEllipse(QRect(w - 50, h - h / 4, w, h - h / 4));
|
||||
}
|
||||
|
||||
if (!m_arrowed)
|
||||
{
|
||||
QPen pen(Qt::transparent);
|
||||
int portion = this->rect().width() / 10;
|
||||
QPoint cpt = this->rect().center();
|
||||
int p = rect().width() - 10;
|
||||
|
||||
int mar = 10;
|
||||
|
||||
pen.setWidth(4);
|
||||
pen.setColor(Qt::black);
|
||||
painter.setPen(pen);
|
||||
|
||||
|
||||
|
||||
painter.drawLine(QPoint(mar + 1, cpt.y() + portion * 3 + 1),
|
||||
QPoint(mar + portion - 1, cpt.y() + portion * 4 - 1));
|
||||
painter.drawLine(QPoint(mar + 1, cpt.y() + portion * 4 - 1),
|
||||
QPoint(mar + portion - 1, cpt.y() + portion * 3 + 1));
|
||||
|
||||
painter.drawLine(QPoint(p - portion, cpt.y() + portion * 4 - portion / 2),
|
||||
QPoint(p, cpt.y() + portion * 4 - portion / 2));
|
||||
painter.drawLine(QPoint(p - portion / 2, cpt.y() + portion * 3),
|
||||
QPoint(p - portion / 2, cpt.y() + portion * 4));
|
||||
|
||||
|
||||
pen.setWidth(2);
|
||||
pen.setColor(Qt::white);
|
||||
painter.setPen(pen);
|
||||
|
||||
painter.drawLine(QPoint(mar + 1, cpt.y() + portion * 3 + 1),
|
||||
QPoint(mar + portion - 1, cpt.y() + portion * 4 - 1));
|
||||
painter.drawLine(QPoint(mar + 1, cpt.y() + portion * 4 - 1),
|
||||
QPoint(mar + portion - 1, cpt.y() + portion * 3 + 1));
|
||||
painter.drawLine(QPoint(p - portion, cpt.y() + portion * 4 - portion / 2),
|
||||
QPoint(p, cpt.y() + portion * 4 - portion / 2));
|
||||
painter.drawLine(QPoint(p - portion / 2, cpt.y() + portion * 3),
|
||||
QPoint(p - portion / 2, cpt.y() + portion * 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
QPen pen(Qt::transparent);
|
||||
pen.setWidth(2);
|
||||
pen.setColor(Qt::white);
|
||||
painter.setPen(pen);
|
||||
//把直径平均分成10份
|
||||
int portion = this->rect().width() / 10;
|
||||
//圆中心点坐标
|
||||
QPoint cpt = this->rect().center();
|
||||
//绘制左边直线
|
||||
painter.drawLine(QPoint(cpt.x() - portion / 2, cpt.y() + portion * 4),
|
||||
QPoint(cpt.x(), cpt.y() + portion * 4 - portion / 2));
|
||||
//绘制右边直线
|
||||
painter.drawLine(QPoint(cpt.x() + portion / 2, cpt.y() + portion * 4),
|
||||
QPoint(cpt.x(), cpt.y() + portion * 4 - portion / 2));
|
||||
}
|
||||
|
||||
QWidget::paintEvent(e);
|
||||
}
|
||||
|
||||
void AvatarWidget::enterEvent(QEvent *)
|
||||
{
|
||||
m_hover = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::leaveEvent(QEvent *)
|
||||
{
|
||||
m_hover = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void AvatarWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
QUrl url(m_avatarPath);
|
||||
m_avatar = QPixmap(url.toLocalFile()).scaled(size() * ratio, Qt::KeepAspectRatio, Qt::FastTransformation);
|
||||
m_avatar.setDevicePixelRatio(ratio);
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* kirigaya <kirigaya@mkacg.com>
|
||||
* Hualet <mr.asianwang@gmail.com>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
* kirigaya <kirigaya@mkacg.com>
|
||||
* Hualet <mr.asianwang@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef AVATARWIDGET_H
|
||||
#define AVATARWIDGET_H
|
||||
|
||||
//#include "avatardel.h"
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
|
||||
#define PIX_SIZE 60
|
||||
|
||||
|
||||
class AvatarWidget : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AvatarWidget(QWidget *parent = 0);
|
||||
explicit AvatarWidget(const QString &avatar, QWidget *parent = 0);
|
||||
|
||||
void setSelected(const bool selected = true);
|
||||
void setDeletable(const bool deletable = true);
|
||||
|
||||
const QString avatarPath() const;
|
||||
void setAvatarPath(const QString &avatar);
|
||||
void setAvatarPixmap(const QPixmap avatar);
|
||||
|
||||
void setArrowed(const bool arrowed = true);
|
||||
inline bool arrowed() const { return m_arrowed; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked(const QString &iconPath) const;
|
||||
void addClicked(const QString &iconPath) const;
|
||||
void removeClicked(const QString &iconPath) const;
|
||||
void requestDelete(const QString &iconPath) const;
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
bool m_hover;
|
||||
bool m_deleable;
|
||||
bool m_selected;
|
||||
bool m_arrowed;
|
||||
|
||||
QPixmap m_avatar;
|
||||
QString m_avatarPath;
|
||||
};
|
||||
|
||||
|
||||
#endif // AVATARWIDGET_H
|
||||
@@ -0,0 +1,156 @@
|
||||
#include "bigcolorbutton.h"
|
||||
|
||||
//#include "utils/baseutils.h"
|
||||
//#include "utils/configsettings.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
const qreal COLOR_RADIUS = 4;
|
||||
const int BTN_RADIUS = 8;
|
||||
const QPoint CENTER_POINT = QPoint(12, 12);
|
||||
|
||||
BigColorButton::BigColorButton(const QString &group, QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
, m_isHover(false)
|
||||
, m_isChecked(false)
|
||||
{
|
||||
setFixedSize(24, 24);
|
||||
setCheckable(false);
|
||||
m_group = group;
|
||||
|
||||
/*
|
||||
if (group == "common")
|
||||
{
|
||||
bool transColBtnChecked = ConfigSettings::instance()->value(
|
||||
"common", "fillColor_transparent").toBool();
|
||||
if (transColBtnChecked)
|
||||
{
|
||||
m_color = QColor(Qt::transparent);
|
||||
} else {
|
||||
m_color = QColor(ConfigSettings::instance()->value(
|
||||
"common", "fillColor").toString());
|
||||
}
|
||||
} else {
|
||||
bool transColBtnChecked = ConfigSettings::instance()->value(
|
||||
"text", "fillColor_transparent").toBool();
|
||||
if (transColBtnChecked)
|
||||
{
|
||||
m_color = QColor(Qt::transparent);
|
||||
} else {
|
||||
m_color = QColor(ConfigSettings::instance()->value(
|
||||
"text", "fillColor").toString());
|
||||
}
|
||||
}
|
||||
|
||||
connect(ConfigSettings::instance(), &ConfigSettings::configChanged,
|
||||
this, &BigColorButton::updateConfigColor);
|
||||
*/
|
||||
}
|
||||
|
||||
void BigColorButton::updateConfigColor(const QString &group,
|
||||
const QString &key)
|
||||
{
|
||||
if (group == m_group && (key == "fillColor"/* || key == "fillColor_alpha"*/
|
||||
|| key == "fillColor_transparent"))
|
||||
{
|
||||
/*
|
||||
qDebug() << "updateConfigColor......" << key;
|
||||
m_color = QColor(ConfigSettings::instance()->value(
|
||||
m_group, "fillColor").toString());
|
||||
|
||||
bool transColBtnChecked = ConfigSettings::instance()->value(m_group,
|
||||
"fillColor_transparent").toBool();
|
||||
if (transColBtnChecked)
|
||||
m_color = QColor(Qt::transparent);
|
||||
else {
|
||||
m_color = QColor(ConfigSettings::instance()->value(
|
||||
m_group, "fillColor").toString());
|
||||
}
|
||||
*/
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
BigColorButton::~BigColorButton()
|
||||
{
|
||||
}
|
||||
|
||||
void BigColorButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing
|
||||
|QPainter::SmoothPixmapTransform);
|
||||
painter.setPen(Qt::transparent);
|
||||
|
||||
painter.setBrush(QBrush(QColor(0, 0, 0, 13)));
|
||||
QColor drawColor = m_color;
|
||||
|
||||
if (m_isHover || m_isChecked)
|
||||
{
|
||||
painter.setBrush(QBrush(QColor(0, 0, 0, 25)));
|
||||
painter.drawRoundedRect(rect(), 4, 4);
|
||||
} else if (m_isChecked)
|
||||
{
|
||||
drawColor = QColor(m_color.red(), m_color.green(), m_color.blue(), 25);
|
||||
}
|
||||
|
||||
painter.setBrush(drawColor);
|
||||
painter.drawEllipse(CENTER_POINT, BTN_RADIUS, BTN_RADIUS);
|
||||
|
||||
QPen borderPen;
|
||||
borderPen.setWidth(1);
|
||||
borderPen.setColor(QColor(0, 0, 0, 15));
|
||||
painter.setPen(borderPen);
|
||||
if (m_isChecked)
|
||||
{
|
||||
painter.setBrush(QColor(0, 0, 0, 55));
|
||||
} else {
|
||||
painter.setBrush(Qt::transparent);
|
||||
}
|
||||
painter.drawEllipse(CENTER_POINT, BTN_RADIUS + 1, BTN_RADIUS+1);
|
||||
}
|
||||
|
||||
void BigColorButton::setColor(QColor color)
|
||||
{
|
||||
m_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void BigColorButton::setColorIndex(int index)
|
||||
{
|
||||
//m_color = colorIndexOf(index);
|
||||
update();
|
||||
}
|
||||
|
||||
void BigColorButton::enterEvent(QEvent *)
|
||||
{
|
||||
if (!m_isHover)
|
||||
{
|
||||
m_isHover = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void BigColorButton::leaveEvent(QEvent *)
|
||||
{
|
||||
if (m_isHover)
|
||||
{
|
||||
m_isHover = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void BigColorButton::mousePressEvent(QMouseEvent* )
|
||||
{
|
||||
m_isChecked = !m_isChecked;
|
||||
update();
|
||||
|
||||
btnCheckStateChanged(m_isChecked);
|
||||
}
|
||||
|
||||
void BigColorButton::resetChecked()
|
||||
{
|
||||
m_isChecked = false;
|
||||
update();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef BIGCOLORBUTTON_H
|
||||
#define BIGCOLORBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
|
||||
//#include "utils/baseutils.h"
|
||||
|
||||
class BigColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BigColorButton(const QString &group, QWidget* parent = 0);
|
||||
~BigColorButton();
|
||||
|
||||
void setColor(QColor color);
|
||||
void setColorIndex(int index);
|
||||
void updateConfigColor(const QString &group, const QString &key);
|
||||
void resetChecked();
|
||||
|
||||
signals:
|
||||
void btnCheckStateChanged(bool show);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void mousePressEvent(QMouseEvent* );
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
bool m_isHover;
|
||||
bool m_isChecked;
|
||||
|
||||
QString m_group;
|
||||
};
|
||||
|
||||
#endif // BIGCOLORBUTTON_H
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "bordercolorbutton.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
//#include "utils/baseutils.h"
|
||||
//#include "utils/configsettings.h"
|
||||
|
||||
const qreal COLOR_RADIUS = 4;
|
||||
const int BTN_RADIUS = 8;
|
||||
const QPoint CENTER_POINT = QPoint(12, 12);
|
||||
|
||||
BorderColorButton::BorderColorButton(QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
, m_isHover(false)
|
||||
, m_isChecked(false)
|
||||
{
|
||||
setFixedSize(24, 24);
|
||||
setCheckable(false);
|
||||
//m_color = QColor(ConfigSettings::instance()->value("common", "strokeColor").toString());
|
||||
qDebug() << "^^^^" << m_color.name();
|
||||
update();
|
||||
|
||||
//connect(ConfigSettings::instance(), &ConfigSettings::configChanged,
|
||||
// this, &BorderColorButton::updateConfigColor);
|
||||
}
|
||||
|
||||
void BorderColorButton::updateConfigColor(const QString &group,
|
||||
const QString &key)
|
||||
{
|
||||
if (group == "common" && (key == "strokeColor" || "strokeColor_transparent"))
|
||||
{
|
||||
//m_color = QColor(ConfigSettings::instance()->value(group, "strokeColor").toString());
|
||||
bool transColBtnChecked;// = ConfigSettings::instance()->value(group, "strokeColor_transparent").toBool();
|
||||
|
||||
if (transColBtnChecked)
|
||||
{
|
||||
m_color = QColor(Qt::transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_color = QColor(ConfigSettings::instance()->value(group, "strokeColor").toString());
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
BorderColorButton::~BorderColorButton()
|
||||
{
|
||||
}
|
||||
|
||||
void BorderColorButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing
|
||||
|QPainter::SmoothPixmapTransform);
|
||||
painter.setPen(Qt::transparent);
|
||||
|
||||
QColor drawColor = m_color;
|
||||
qDebug() << "~~~~~~~" << drawColor.name();
|
||||
if (m_isChecked || m_isHover)
|
||||
{
|
||||
painter.setBrush(QBrush(QColor(0, 0, 0, 25)));
|
||||
painter.drawRoundedRect(rect(), 4, 4);
|
||||
} else if (m_isChecked)
|
||||
{
|
||||
drawColor = QColor(m_color.red(), m_color.green(), m_color.black(), 25);
|
||||
} else
|
||||
{
|
||||
painter.setBrush(Qt::transparent);
|
||||
painter.drawRoundedRect(rect(), 4, 4);
|
||||
}
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
pen.setColor(drawColor);
|
||||
painter.setPen(pen);
|
||||
painter.setBrush(Qt::transparent);
|
||||
painter.drawEllipse(CENTER_POINT, BTN_RADIUS, BTN_RADIUS);
|
||||
|
||||
QPen borderPen;
|
||||
borderPen.setWidth(1);
|
||||
borderPen.setColor(QColor(0, 0, 0, 15));
|
||||
painter.setPen(borderPen);
|
||||
painter.drawEllipse(CENTER_POINT, BTN_RADIUS + 1, BTN_RADIUS + 1);
|
||||
if (m_isChecked)
|
||||
{
|
||||
painter.setBrush(QColor(0, 0, 0, 35));
|
||||
painter.drawEllipse(CENTER_POINT, BTN_RADIUS - 1, BTN_RADIUS - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void BorderColorButton::setColor(QColor color)
|
||||
{
|
||||
m_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void BorderColorButton::setColorIndex(int index)
|
||||
{
|
||||
//m_color = colorIndexOf(index);
|
||||
update();
|
||||
}
|
||||
|
||||
void BorderColorButton::resetChecked()
|
||||
{
|
||||
m_isChecked = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void BorderColorButton::enterEvent(QEvent *)
|
||||
{
|
||||
if (!m_isHover)
|
||||
{
|
||||
m_isHover = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void BorderColorButton::leaveEvent(QEvent *)
|
||||
{
|
||||
if (m_isHover)
|
||||
{
|
||||
m_isHover = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void BorderColorButton::mousePressEvent(QMouseEvent* )
|
||||
{
|
||||
m_isChecked = !m_isChecked;
|
||||
btnCheckStateChanged(m_isChecked);
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef BORDERCOLORBUTTON_H
|
||||
#define BORDERCOLORBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class BorderColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BorderColorButton(QWidget* parent = 0);
|
||||
~BorderColorButton();
|
||||
|
||||
void setColor(QColor color);
|
||||
void setColorIndex(int index);
|
||||
void updateCheckedStatus();
|
||||
void updateConfigColor(const QString &group, const QString &key);
|
||||
void resetChecked();
|
||||
|
||||
signals:
|
||||
void btnCheckStateChanged(bool checked);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void mousePressEvent(QMouseEvent* );
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
bool m_isHover;
|
||||
bool m_isChecked;
|
||||
};
|
||||
|
||||
#endif // BORDERCOLORBUTTON_H
|
||||
@@ -0,0 +1,172 @@
|
||||
#include "colorlabel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
#include <QImage>
|
||||
#include <cmath>
|
||||
|
||||
//#include "utils/baseutils.h"
|
||||
|
||||
const QSize COLOR_TIPS_SIZE = QSize(50, 50);
|
||||
|
||||
ColorLabel::ColorLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, m_picking(true)
|
||||
, m_pressed(false)
|
||||
, m_tipPoint(this->rect().center())
|
||||
, m_workToPick(false)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
connect(this, &ColorLabel::clicked, this, [=]{
|
||||
if (m_picking && m_workToPick)
|
||||
{
|
||||
qDebug() << "clickedPos:" << m_clickedPos;
|
||||
pickColor(m_clickedPos, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//h∈(0, 360), s∈(0, 1), v∈(0, 1)
|
||||
QColor ColorLabel::getColor(qreal h, qreal s, qreal v)
|
||||
{
|
||||
int hi = int(h/60)%6;
|
||||
qreal f = h/60 - hi;
|
||||
|
||||
qreal p = v*(1 - s);
|
||||
qreal q = v*(1 - f*s);
|
||||
qreal t = v*(1 - (1 - f)*s);
|
||||
|
||||
if (hi == 0)
|
||||
{
|
||||
return QColor(std::min(int(255*v), 255), std::min(int(255*t), 255), std::min(int(255*p), 255));
|
||||
} else if (hi == 1)
|
||||
{
|
||||
return QColor(std::min(int(255*q), 255), std::min(int(255*v), 255), std::min(int(255*p), 255));
|
||||
} else if(hi == 2)
|
||||
{
|
||||
return QColor(std::min(int(255*p), 255), std::min(int(255*v), 255), std::min(int(255*t), 255));
|
||||
} else if (hi == 3)
|
||||
{
|
||||
return QColor(std::min(int(255*p), 255), std::min(int(255*q), 255), std::min(int(255*v), 255));
|
||||
} else if(hi == 4)
|
||||
{
|
||||
return QColor(std::min(int(255*t), 255), std::min(int(255*p), 255), std::min(int(255*v), 255));
|
||||
} else
|
||||
{
|
||||
return QColor(std::min(int(255*v), 255), std::min(int(255*p), 255), int(255*q));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorLabel::setHue(int hue)
|
||||
{
|
||||
m_hue = hue;
|
||||
update();
|
||||
}
|
||||
|
||||
void ColorLabel::pickColor(QPoint pos, bool picked)
|
||||
{
|
||||
QPixmap pickPixmap;
|
||||
pickPixmap = this->grab(QRect(0, 0, this->width(), this->height()));
|
||||
QImage pickImg = pickPixmap.toImage();
|
||||
|
||||
if (!pickImg.isNull())
|
||||
{
|
||||
QRgb pickRgb = pickImg.pixel(pos);
|
||||
m_pickedColor = QColor(qRed(pickRgb), qGreen(pickRgb), qBlue(pickRgb));
|
||||
} else
|
||||
{
|
||||
m_pickedColor = QColor(0, 0, 0);
|
||||
}
|
||||
|
||||
if (picked)
|
||||
emit pickedColor(m_pickedColor);
|
||||
}
|
||||
|
||||
QColor ColorLabel::getPickedColor()
|
||||
{
|
||||
return m_pickedColor;
|
||||
}
|
||||
|
||||
void ColorLabel::setPickColor(bool picked)
|
||||
{
|
||||
m_workToPick = picked;
|
||||
}
|
||||
|
||||
void ColorLabel::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
|
||||
QImage backgroundImage(this->width(), this->height(), QImage::Format_ARGB32);
|
||||
for(qreal s = 0; s < this->width(); s++)
|
||||
{
|
||||
for(qreal v = 0; v < this->height(); v++)
|
||||
{
|
||||
QColor penColor = getColor(m_hue, s/this->width(), v/this->height());
|
||||
backgroundImage.setPixelColor(int(s), this->height() - 1 - int(v), penColor);
|
||||
}
|
||||
}
|
||||
|
||||
painter.drawImage(this->rect(), backgroundImage);
|
||||
}
|
||||
|
||||
void ColorLabel::enterEvent(QEvent *e)
|
||||
{
|
||||
if (!m_workToPick)
|
||||
return;
|
||||
|
||||
m_lastCursor = this->cursor();
|
||||
//qApp->setOverrideCursor(pickColorCursor());
|
||||
QLabel::enterEvent(e);
|
||||
}
|
||||
|
||||
void ColorLabel::leaveEvent(QEvent *e)
|
||||
{
|
||||
if (!m_workToPick)
|
||||
return;
|
||||
|
||||
qApp->setOverrideCursor(m_lastCursor);
|
||||
QLabel::leaveEvent(e);
|
||||
}
|
||||
|
||||
void ColorLabel::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_workToPick)
|
||||
return ;
|
||||
|
||||
m_pressed = true;
|
||||
m_tipPoint = this->mapFromGlobal(cursor().pos());
|
||||
pickColor(m_tipPoint, true);
|
||||
QLabel::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void ColorLabel::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_workToPick)
|
||||
return;
|
||||
|
||||
if (m_pressed)
|
||||
{
|
||||
m_tipPoint = this->mapFromGlobal(cursor().pos());
|
||||
pickColor(m_tipPoint, true);
|
||||
}
|
||||
update();
|
||||
QLabel::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void ColorLabel::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (m_pressed)
|
||||
{
|
||||
m_clickedPos = e->pos();
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
m_pressed = false;
|
||||
QLabel::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
ColorLabel::~ColorLabel()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef COLORLABEL_H
|
||||
#define COLORLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
#include <QEnterEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QCursor>
|
||||
|
||||
class ColorLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorLabel(QWidget* parent = 0);
|
||||
~ColorLabel();
|
||||
|
||||
//h∈(0, 360), s∈(0, 1), v∈(0, 1)
|
||||
QColor getColor(qreal h, qreal s, qreal v);
|
||||
void setHue(int hue);
|
||||
|
||||
void pickColor(QPoint pos, bool picked = false);
|
||||
QColor getPickedColor();
|
||||
void setPickColor(bool picked);
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
void pickedColor(QColor color);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
void enterEvent(QEvent* e);
|
||||
void leaveEvent(QEvent* e);
|
||||
void mousePressEvent(QMouseEvent* e);
|
||||
void mouseMoveEvent(QMouseEvent* e);
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
|
||||
private:
|
||||
//calculate the color's rgb value in pos.
|
||||
QColor calColorAtPoint(QPointF pos);
|
||||
QCursor m_lastCursor;
|
||||
int m_hue = 0;
|
||||
bool m_workToPick;
|
||||
bool m_picking;
|
||||
bool m_pressed;
|
||||
QColor m_pickedColor;
|
||||
QPoint m_clickedPos;
|
||||
QPoint m_tipPoint;
|
||||
};
|
||||
|
||||
#endif // COLORLABEL_H
|
||||
@@ -0,0 +1,375 @@
|
||||
#include "colorpanel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QButtonGroup>
|
||||
#include <QDebug>
|
||||
|
||||
#include "utils/global.h"
|
||||
#include "utils/baseutils.h"
|
||||
#include "utils/configsettings.h"
|
||||
#include "colorlabel.h"
|
||||
#include "colorslider.h"
|
||||
#include "pickcolorwidget.h"
|
||||
|
||||
const int ORGIN_WIDTH = 250;
|
||||
const int PANEL_WIDTH = 222;
|
||||
const int ORIGIN_HEIGHT = 176; //213;
|
||||
const int EXPAND_HEIGHT = 391; //430;
|
||||
const int RADIUS = 0;
|
||||
const int BORDER_WIDTH = 2;
|
||||
const QSize COLOR_BORDER_SIZE = QSize(20, 20);
|
||||
const QSize COLOR_BUTTN = QSize(14, 14);
|
||||
const QSize SLIDER_SIZE = QSize(178, 22);
|
||||
const QSize BTN_SIZE = QSize(24, 24);
|
||||
|
||||
|
||||
ColorButton::ColorButton(const QColor &color, QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
, m_disable(false)
|
||||
{
|
||||
m_color = color;
|
||||
setFixedSize(COLOR_BORDER_SIZE);
|
||||
setCheckable(true);
|
||||
|
||||
connect(this, &ColorButton::clicked, this, [=]{
|
||||
setChecked(true);
|
||||
if (m_disable)
|
||||
{
|
||||
emit colorButtonClicked(Qt::transparent);
|
||||
} else
|
||||
{
|
||||
emit colorButtonClicked(m_color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ColorButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing);
|
||||
painter.setPen(m_color);
|
||||
|
||||
if (m_color == QColor(Qt::transparent))
|
||||
{
|
||||
painter.drawPixmap(QRect(3, 3, this->width() - 6, this->height() - 6),
|
||||
QPixmap(":/theme/light/images/draw/color_disable_active.png"));
|
||||
if (isChecked())
|
||||
{
|
||||
painter.setBrush(QBrush());
|
||||
QPen borderPen;
|
||||
borderPen.setWidth(BORDER_WIDTH);
|
||||
borderPen.setColor("#01bdff");
|
||||
painter.setPen(borderPen);
|
||||
painter.drawRoundedRect(QRect(1, 1, this->width() - 2,
|
||||
this->height() - 2), RADIUS, RADIUS);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
painter.setBrush(QBrush(m_color));
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(1);
|
||||
pen.setColor(QColor(0, 0, 0, 26));
|
||||
painter.setPen(pen);
|
||||
painter.drawRoundedRect(QRect(3, 3, this->width() - 6,
|
||||
this->height() - 6), RADIUS, RADIUS);
|
||||
|
||||
if (isChecked())
|
||||
{
|
||||
painter.setBrush(QBrush());
|
||||
QPen borderPen;
|
||||
borderPen.setWidth(BORDER_WIDTH);
|
||||
borderPen.setColor("#01bdff");
|
||||
painter.setPen(borderPen);
|
||||
painter.drawRoundedRect(QRect(1, 1, this->width() - 2,
|
||||
this->height() - 2), RADIUS, RADIUS);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorButton::setDisableColor(bool disable)
|
||||
{
|
||||
m_disable = disable;
|
||||
}
|
||||
|
||||
ColorButton::~ColorButton()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ColorPanel::ColorPanel(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_expand(false)
|
||||
, m_drawstatus(DrawStatus::Fill)
|
||||
{
|
||||
DRAW_THEME_INIT_WIDGET("ColorPanel");
|
||||
QWidget* colorBtnWidget = new QWidget(this);
|
||||
colorBtnWidget->setFixedSize(ORGIN_WIDTH, ORIGIN_HEIGHT);
|
||||
|
||||
if (!m_expand)
|
||||
setFixedSize(ORGIN_WIDTH, ORIGIN_HEIGHT);
|
||||
else
|
||||
setFixedSize(ORGIN_WIDTH, EXPAND_HEIGHT);
|
||||
|
||||
m_colList = specifiedColorList();
|
||||
|
||||
QButtonGroup* colorsButtonGroup = new QButtonGroup(this);
|
||||
colorsButtonGroup->setExclusive(true);
|
||||
|
||||
QGridLayout* gLayout = new QGridLayout;
|
||||
gLayout->setVerticalSpacing(3);
|
||||
gLayout->setHorizontalSpacing(3);
|
||||
|
||||
for(int i = 0; i < m_colList.length(); i++)
|
||||
{
|
||||
ColorButton* cb = new ColorButton(m_colList[i], this);
|
||||
if (i == 0)
|
||||
cb->setDisableColor(true);
|
||||
m_cButtonList.append(cb);
|
||||
gLayout->addWidget(cb, i/10, i%10);
|
||||
colorsButtonGroup->addButton(cb);
|
||||
qDebug() << "~~~" << i/10 << i%10;
|
||||
connect(cb, &ColorButton::colorButtonClicked, this, &ColorPanel::setConfigColor);
|
||||
}
|
||||
/*
|
||||
m_sliderLabel = new SliderLabel(tr("Alpha"), m_drawstatus,m_widgetStatus, this);
|
||||
connect(m_sliderLabel, &SliderLabel::alphaChanged, this, [=](int value)
|
||||
{
|
||||
if (m_widgetStatus != MiddleWidgetStatus::DrawText)
|
||||
{
|
||||
if (m_drawstatus == DrawStatus::Stroke)
|
||||
{
|
||||
ConfigSettings::instance()->setValue("common", "strokeColor_alpha", value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigSettings::instance()->setValue("common", "fillColor_alpha", value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigSettings::instance()->setValue("text", "fillColor_alpha", value);
|
||||
}
|
||||
});
|
||||
connect(ConfigSettings::instance(), &ConfigSettings::configChanged, this,
|
||||
[=](const QString &group, const QString &key)
|
||||
{
|
||||
Q_UNUSED(group);
|
||||
if (key == "fillColor_alpha" || key == "strokeColor_alpha")
|
||||
{
|
||||
m_sliderLabel->updateDrawStatus(m_drawstatus, m_widgetStatus);
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
QWidget* colorValueWidget = new QWidget;
|
||||
colorValueWidget->setFixedWidth(PANEL_WIDTH);
|
||||
|
||||
QLabel* colLabel = new QLabel(colorValueWidget);
|
||||
colLabel->setObjectName("ColorLabel");
|
||||
colLabel->setFixedWidth(48);
|
||||
colLabel->setText(tr("Color"));
|
||||
|
||||
m_colLineEdit = new QLineEdit(colorValueWidget);
|
||||
m_colLineEdit->setObjectName("ColorLineEdit");
|
||||
m_colLineEdit->setFixedSize(145, 24);
|
||||
|
||||
m_colorfulBtn = new QPushButton(colorValueWidget);
|
||||
m_colorfulBtn->setObjectName("ColorFulButton");
|
||||
m_colorfulBtn->setFixedSize(BTN_SIZE);
|
||||
m_colorfulBtn->setText("+");
|
||||
m_colorfulBtn->setToolTip("<html><head/><body><p>Enseñar más colores</p></body></html>");
|
||||
m_colorfulBtn->show();
|
||||
|
||||
QHBoxLayout* colorLayout = new QHBoxLayout(colorValueWidget);
|
||||
colorLayout->setMargin(0);
|
||||
colorLayout->setSpacing(0);
|
||||
colorLayout->addWidget(colLabel);
|
||||
colorLayout->addWidget(m_colLineEdit);
|
||||
colorLayout->addSpacing(5);
|
||||
colorLayout->addWidget(m_colorfulBtn);
|
||||
|
||||
PickColorWidget* pickColWidget = new PickColorWidget(this);
|
||||
connect(this, &ColorPanel::resetColorButtons, this, [=]{
|
||||
colorsButtonGroup->setExclusive(false);
|
||||
foreach (ColorButton* cb, m_cButtonList) {
|
||||
cb->setChecked(false);
|
||||
}
|
||||
colorsButtonGroup->setExclusive(true);
|
||||
});
|
||||
connect(pickColWidget, &PickColorWidget::pickedColor, this,
|
||||
[=](QColor color)
|
||||
{
|
||||
Q_UNUSED(color);
|
||||
emit resetColorButtons();
|
||||
});
|
||||
|
||||
connect(pickColWidget, &PickColorWidget::pickedColor, this,
|
||||
&ColorPanel::setConfigColor);
|
||||
|
||||
connect(m_colLineEdit, &QLineEdit::textChanged, this, [=](QString text){
|
||||
if (QColor(text).isValid())
|
||||
{
|
||||
pickColWidget->setRgbValue(QColor(text));
|
||||
}
|
||||
});
|
||||
|
||||
QVBoxLayout* vLayout = new QVBoxLayout(colorBtnWidget);
|
||||
vLayout->setContentsMargins(4, 4, 7, 4);
|
||||
vLayout->setSpacing(0);
|
||||
vLayout->addSpacing(5);
|
||||
vLayout->addLayout(gLayout);
|
||||
vLayout->addSpacing(9);
|
||||
//vLayout->addWidget(m_sliderLabel, 0, Qt::AlignCenter);
|
||||
//vLayout->addSpacing(14);
|
||||
vLayout->addWidget(colorValueWidget, 0, Qt::AlignCenter);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(colorBtnWidget);
|
||||
layout->addWidget(pickColWidget, 0, Qt::AlignCenter);
|
||||
|
||||
if (!m_expand)
|
||||
pickColWidget->hide();
|
||||
|
||||
connect(m_colorfulBtn, &QPushButton::clicked, this, [=]{
|
||||
if (m_expand)
|
||||
{
|
||||
pickColWidget->hide();
|
||||
pickColWidget->setPickedColor(false);
|
||||
setFixedHeight(ORIGIN_HEIGHT);
|
||||
updateGeometry();
|
||||
} else
|
||||
{
|
||||
pickColWidget->show();
|
||||
pickColWidget->setPickedColor(true);
|
||||
setFixedHeight(EXPAND_HEIGHT);
|
||||
updateGeometry();
|
||||
}
|
||||
emit updateHeight();
|
||||
|
||||
m_expand = !m_expand;
|
||||
});
|
||||
}
|
||||
|
||||
void ColorPanel::setColor(QColor color)
|
||||
{
|
||||
Q_UNUSED(color);
|
||||
}
|
||||
|
||||
void ColorPanel::setDrawStatus(DrawStatus status)
|
||||
{
|
||||
m_drawstatus = status;
|
||||
|
||||
QString colorName;
|
||||
if (m_drawstatus == DrawStatus::Stroke)
|
||||
{
|
||||
colorName = ConfigSettings::instance()->value("common",
|
||||
"strokeColor").toString();
|
||||
} else
|
||||
{
|
||||
colorName = ConfigSettings::instance()->value("common",
|
||||
"fillColor").toString();
|
||||
}
|
||||
m_colLineEdit->setText(colorName);
|
||||
//m_sliderLabel->updateDrawStatus(m_drawstatus, m_widgetStatus);
|
||||
}
|
||||
|
||||
void ColorPanel::setConfigColor(QColor color)
|
||||
{
|
||||
m_colLineEdit->setText(color.name());
|
||||
if (m_widgetStatus != MiddleWidgetStatus::DrawText)
|
||||
{
|
||||
if (m_drawstatus == DrawStatus::Stroke)
|
||||
{
|
||||
qDebug() << "setConfigColor" << color.name();
|
||||
updateConfigByWidget("common", "strokeColor", color);
|
||||
} else {
|
||||
updateConfigByWidget("common", "fillColor", color);
|
||||
}
|
||||
} else {
|
||||
updateConfigByWidget("text", "fillColor", color);
|
||||
}
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
void ColorPanel::updateConfigByWidget(const QString &group,
|
||||
const QString &key, QColor color)
|
||||
{
|
||||
if (color == QColor(Qt::transparent))
|
||||
{
|
||||
ConfigSettings::instance()->setValue(group,
|
||||
QString("%1_transparent").arg(key), true);
|
||||
} else {
|
||||
ConfigSettings::instance()->setValue(group,
|
||||
QString("%1_transparent").arg(key), false);
|
||||
ConfigSettings::instance()->setValue(group, key, color.name());
|
||||
qDebug() << "updateCofigByWidget:" << group << key << color.name();
|
||||
//m_sliderLabel->setAlpha(100);
|
||||
}
|
||||
}
|
||||
/*
|
||||
void ColorPanel::updateColorAlpha(DrawStatus status,
|
||||
MiddleWidgetStatus widgetStatus)
|
||||
{
|
||||
m_sliderLabel->updateDrawStatus(status, widgetStatus);
|
||||
}
|
||||
*/
|
||||
|
||||
void ColorPanel::setMiddleWidgetStatus(MiddleWidgetStatus status)
|
||||
{
|
||||
m_widgetStatus = status;
|
||||
}
|
||||
|
||||
void ColorPanel::updateColorButtonStatus()
|
||||
{
|
||||
if (m_widgetStatus != MiddleWidgetStatus::DrawText)
|
||||
{
|
||||
if (m_drawstatus == DrawStatus::Stroke)
|
||||
{
|
||||
updateColorBtnByWidget("common", "strokeColor");
|
||||
} else {
|
||||
updateColorBtnByWidget("common", "fillColor");
|
||||
}
|
||||
} else {
|
||||
updateColorBtnByWidget("text", "fillColor");
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPanel::updateColorBtnByWidget(const QString &group,const QString &key)
|
||||
{
|
||||
bool transColorBtnChecked = ConfigSettings::instance()->value(group, QString("%1_transparent").arg(key)).toBool();
|
||||
if (transColorBtnChecked)
|
||||
{
|
||||
m_cButtonList[0]->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString colorName = ConfigSettings::instance()->value(group,QString("%1").arg(key)).toString();
|
||||
if (m_colList.contains(colorName))
|
||||
{
|
||||
m_cButtonList[m_colList.indexOf(colorName)]->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
resetColorButtons();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColorPanel::~ColorPanel()
|
||||
{
|
||||
}
|
||||
|
||||
QColor ColorPanel::getColor()
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef COLORPANEL_H
|
||||
#define COLORPANEL_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
#include <QColor>
|
||||
#include <QPaintEvent>
|
||||
#include <QApplication>
|
||||
|
||||
#include "sliderlabel.h"
|
||||
#include "editlabel.h"
|
||||
//#include "utils/baseutils.h"
|
||||
|
||||
class ColorButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorButton(const QColor &color, QWidget* parent = 0);
|
||||
~ColorButton();
|
||||
|
||||
void setDisableColor(bool disable);
|
||||
|
||||
signals:
|
||||
void colorButtonClicked(QColor color);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
bool m_disable;
|
||||
};
|
||||
|
||||
class ColorPanel : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorPanel(QWidget* parent = 0);
|
||||
~ColorPanel();
|
||||
|
||||
void updateColorButtonStatus();
|
||||
void updateColorBtnByWidget(const QString &group, const QString &key);
|
||||
void updateConfigByWidget(const QString &group, const QString &key,
|
||||
QColor color);
|
||||
//void updateColorAlpha(DrawStatus status, MiddleWidgetStatus widgetStatus);
|
||||
|
||||
void setColor(QColor color);
|
||||
void setDrawStatus(DrawStatus status);
|
||||
void setConfigColor(QColor color);
|
||||
void setMiddleWidgetStatus(MiddleWidgetStatus status);
|
||||
|
||||
QColor getColor();
|
||||
|
||||
signals:
|
||||
void colorChanged(QColor color);
|
||||
void updateHeight();
|
||||
void resetColorButtons();
|
||||
|
||||
private:
|
||||
SliderLabel* m_sliderLabel;
|
||||
QLineEdit* m_colLineEdit;
|
||||
QPushButton* m_colorfulBtn;
|
||||
|
||||
QList<QColor> m_colList;
|
||||
QList<ColorButton*> m_cButtonList;
|
||||
DrawStatus m_drawstatus;
|
||||
MiddleWidgetStatus m_widgetStatus;
|
||||
bool m_expand;
|
||||
|
||||
QColor m_color;
|
||||
};
|
||||
|
||||
#endif // COLORPANEL_H
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "colorslider.h"
|
||||
|
||||
#include <QStyleOptionSlider>
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QStyle>
|
||||
|
||||
ColorSlider::ColorSlider(QWidget *parent)
|
||||
: QSlider(parent) {
|
||||
setMinimum(0);
|
||||
setMaximum(360);
|
||||
setOrientation(Qt::Horizontal);
|
||||
this->setRange(5, 355);
|
||||
setFixedSize(222, 14);
|
||||
setStyleSheet("ColorSlider::handle:horizontal {"
|
||||
"border: 1px solid rgba(0, 0, 0, 26);"
|
||||
"width: 4px;"
|
||||
"margin: 0;}"
|
||||
);
|
||||
}
|
||||
|
||||
ColorSlider::~ColorSlider()
|
||||
{
|
||||
}
|
||||
|
||||
//h∈(0, 360), s∈(0, 1), v∈(0, 1)
|
||||
QColor ColorSlider::getColor(qreal h, qreal s, qreal v) {
|
||||
int hi = int(h/60)%6;
|
||||
qreal f = h/60 - hi;
|
||||
|
||||
qreal p = v*(1 - s);
|
||||
qreal q = v*(1 - f*s);
|
||||
qreal t = v*(1- (1 - f)*s);
|
||||
|
||||
if (hi == 0) {
|
||||
return QColor(std::min(int(255*v), 255), std::min(int(255*t), 255), std::min(int(255*p), 255));
|
||||
} else if (hi == 1) {
|
||||
return QColor(std::min(int(255*q), 255), std::min(int(255*v), 255), std::min(int(255*p), 255));
|
||||
} else if(hi == 2) {
|
||||
return QColor(std::min(int(255*p), 255), std::min(int(255*v), 255), std::min(int(255*t), 255));
|
||||
} else if (hi == 3) {
|
||||
return QColor(std::min(int(255*p), 255), std::min(int(255*q), 255), std::min(int(255*v), 255));
|
||||
} else if(hi == 4) {
|
||||
return QColor(std::min(int(255*t), 255), std::min(int(255*p), 255), std::min(int(255*v), 255));
|
||||
} else {
|
||||
return QColor(std::min(int(255*v), 255), std::min(int(255*p), 255), int(255*q));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorSlider::paintEvent(QPaintEvent *ev)
|
||||
{
|
||||
QStyleOptionSlider opt;
|
||||
initStyleOption(&opt);
|
||||
|
||||
opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
|
||||
if (tickPosition() != NoTicks)
|
||||
{
|
||||
opt.subControls |= QStyle::SC_SliderTickmarks;
|
||||
}
|
||||
|
||||
QRect groove_rect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
|
||||
int spacing = 6;
|
||||
QRect rect(groove_rect.left(), groove_rect.top(), groove_rect.width() + 1, groove_rect.height());
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QImage backgroundImage(rect.width(), rect.height() - spacing, QImage::Format_ARGB32);
|
||||
|
||||
for(qreal s = 0; s <= backgroundImage.width(); s++)
|
||||
{
|
||||
for(qreal v = 0; v <= backgroundImage.height(); v++)
|
||||
{
|
||||
QColor penColor = getColor(qreal(int(s/rect.width()*360)), 1, 1);
|
||||
backgroundImage.setPixelColor(std::min(int(s), rect.width() - 1), backgroundImage.height() - int(v), penColor);
|
||||
}
|
||||
}
|
||||
|
||||
painter.drawImage(QRect(rect.x(), rect.y() + 2, rect.width(), rect.height() - spacing), backgroundImage);
|
||||
QPen borderPen;
|
||||
borderPen.setWidth(1);
|
||||
borderPen.setColor(QColor(0, 0, 0, 26));
|
||||
painter.setPen(borderPen);
|
||||
painter.drawRect(QRect(rect.x(), rect.y() + 3, rect.width() - 2, rect.height() - spacing - 2));
|
||||
QSlider::paintEvent(ev);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef COLORSLIDER_H
|
||||
#define COLORSLIDER_H
|
||||
|
||||
#include <QSlider>
|
||||
#include <QPaintEvent>
|
||||
|
||||
class ColorSlider : public QSlider {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorSlider(QWidget* parent = 0);
|
||||
~ColorSlider();
|
||||
|
||||
//h∈(0, 360), s∈(0, 1), v∈(0, 1)
|
||||
QColor getColor(qreal h, qreal s, qreal v);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *ev);
|
||||
|
||||
private:
|
||||
int m_value;
|
||||
};
|
||||
|
||||
#endif // COLORSLIDER_H
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "companylistitemdelegate.h"
|
||||
#include "mapplication.h"
|
||||
|
||||
CompanyListItemDelegate::CompanyListItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CompanyListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
paintPerson(painter, option, index);
|
||||
}
|
||||
|
||||
QSize CompanyListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize(option.rect.width(), 90);
|
||||
}
|
||||
|
||||
void CompanyListItemDelegate::paintPerson(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
const bool isSelected = option.state & QStyle::State_Selected;
|
||||
const bool isHovered = option.state & QStyle::State_MouseOver;
|
||||
|
||||
|
||||
painter->save();
|
||||
|
||||
/*
|
||||
QLinearGradient backgroundGradient(QPoint(option.rect.x(), option.rect.y()), QPoint(option.rect.x(), option.rect.y()+option.rect.height()));
|
||||
|
||||
if(isSelected)
|
||||
{
|
||||
// painter->fillRect(option.rect, QBrush(QColor(49, 49, 49)));
|
||||
backgroundGradient.setColorAt(0, QColor(109, 164, 219));
|
||||
backgroundGradient.setColorAt(1, QColor(61, 138, 212));
|
||||
painter->fillRect(option.rect, QBrush(backgroundGradient));
|
||||
// painter->fillRect(option.rect, QBrush(QColor(225, 225, 225)));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// painter->fillRect(option.rect, QBrush(QColor(244, 244, 244)));
|
||||
backgroundGradient.setColorAt(0, QColor(245, 245, 245));
|
||||
backgroundGradient.setColorAt(1, QColor(240, 240, 240));
|
||||
painter->fillRect(option.rect, QBrush(backgroundGradient));
|
||||
}
|
||||
|
||||
painter->setPen(QColor(225, 225, 225));
|
||||
if(isSelected)
|
||||
{
|
||||
painter->setPen(QColor(37, 105, 169));
|
||||
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
||||
painter->setPen(Qt::transparent);
|
||||
}
|
||||
painter->drawLine(option.rect.topLeft(), option.rect.topRight());
|
||||
|
||||
if(!isSelected)
|
||||
{
|
||||
painter->setPen(QColor(248, 248, 248));
|
||||
painter->drawLine(QPoint(option.rect.x(), option.rect.y()+1), QPoint(option.rect.x()+option.rect.width(), option.rect.y()+1));
|
||||
}
|
||||
// QString text = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
QRect textRect(option.rect.x()+10, option.rect.y(), option.rect.width()-10, option.rect.height());
|
||||
painter->setPen(QColor(69, 69, 69));
|
||||
QFont textFont(painter->font());
|
||||
textFont.setPixelSize(18);
|
||||
|
||||
if(isSelected)
|
||||
{
|
||||
painter->setPen(QColor(229, 229, 229));
|
||||
}
|
||||
|
||||
painter->setFont(textFont);
|
||||
painter->drawText(textRect, Qt::AlignLeft|Qt::AlignVCenter, tp.name());
|
||||
*/
|
||||
//-------------------------------------------------------------------------------------------
|
||||
/*
|
||||
QFont font = QApplication::font();
|
||||
QFont SubFont = QApplication::font();
|
||||
//font.setPixelSize(font.weight()+);
|
||||
font.setBold(true);
|
||||
SubFont.setWeight(SubFont.weight()-2);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
//item->setData(Name, Qt::DisplayRole);
|
||||
//item->setData(CIF, Qt::UserRole);
|
||||
//item->setData(path, Qt::UserRole+1);
|
||||
|
||||
//QIcon icon = qvariant_cast<QIcon>(index.data(Qt::EditRole));
|
||||
QString headerText = qvariant_cast<QString>(index.data(Qt::DisplayRole));
|
||||
QString subText = qvariant_cast<QString>(index.data(Qt::DisplayRole + 1));
|
||||
//QSize iconsize = icon.actualSize(option.decorationSize);
|
||||
|
||||
|
||||
QRect headerRect = option.rect;
|
||||
QRect subheaderRect = option.rect;
|
||||
QRect iconRect = subheaderRect;
|
||||
|
||||
iconRect.setRight(iconsize.width()+30);
|
||||
iconRect.setTop(iconRect.top()+5);
|
||||
headerRect.setLeft(iconRect.right());
|
||||
subheaderRect.setLeft(iconRect.right());
|
||||
headerRect.setTop(headerRect.top()+5);
|
||||
headerRect.setBottom(headerRect.top()+fm.height());
|
||||
|
||||
subheaderRect.setTop(headerRect.bottom()+2);
|
||||
|
||||
|
||||
//painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height()));
|
||||
painter->drawPixmap(QPoint(iconRect.left()+iconsize.width()/2+2,iconRect.top()+iconsize.height()/2+3),icon.pixmap(iconsize.width(),iconsize.height()));
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(headerRect,headerText);
|
||||
|
||||
|
||||
painter->setFont(SubFont);
|
||||
painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
QLinearGradient backgroundGradient(QPoint(option.rect.x(), option.rect.y()), QPoint(option.rect.x(), option.rect.y()+option.rect.height()));
|
||||
|
||||
if(isSelected)
|
||||
{
|
||||
// painter->fillRect(option.rect, QBrush(QColor(49, 49, 49)));
|
||||
backgroundGradient.setColorAt(0, QColor(109, 164, 219));
|
||||
backgroundGradient.setColorAt(1, QColor(61, 138, 212));
|
||||
painter->fillRect(option.rect, QBrush(backgroundGradient));
|
||||
// painter->fillRect(option.rect, QBrush(QColor(225, 225, 225)));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// painter->fillRect(option.rect, QBrush(QColor(244, 244, 244)));
|
||||
backgroundGradient.setColorAt(0, QColor(245, 245, 245));
|
||||
backgroundGradient.setColorAt(1, QColor(240, 240, 240));
|
||||
painter->fillRect(option.rect, QBrush(backgroundGradient));
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString name = qvariant_cast<QString>(index.data(Qt::DisplayRole));
|
||||
QString cif = qvariant_cast<QString>(index.data(Qt::UserRole));
|
||||
QString path = qvariant_cast<QString>(index.data(Qt::UserRole + 1));
|
||||
|
||||
//painter->setFont(textFont);
|
||||
QRect nameRect(option.rect.x() + 100, option.rect.y() + 10,
|
||||
option.rect.width() - 10, option.rect.height() / 2 - 20);
|
||||
|
||||
QRect cifRect(option.rect.x() + 100, option.rect.y() +option.rect.height() / 2 + 10,
|
||||
option.rect.width() - 10, option.rect.height() / 2 - 20);
|
||||
|
||||
painter->drawText(nameRect, Qt::AlignLeft|Qt::AlignVCenter, name);
|
||||
painter->drawText(cifRect, Qt::AlignLeft|Qt::AlignVCenter, cif);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef COMPANYLISTITEMDELEGATE_H
|
||||
#define COMPANYLISTITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
class CompanyListItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CompanyListItemDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
void paintPerson(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void paintLetter(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif // COMPANYLISTITEMDELEGATE_H
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dlineedit.h"
|
||||
#include "dthememanager.h"
|
||||
#include "private/dlineedit_p.h"
|
||||
#include "darrowrectangle.h"
|
||||
#include "dstyleoption.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QResizeEvent>
|
||||
#include <QWidgetAction>
|
||||
|
||||
#define private public
|
||||
#ifndef slots
|
||||
#define slots Q_SLOTS
|
||||
#endif
|
||||
#include <private/qlineedit_p.h>
|
||||
#undef private
|
||||
|
||||
DWIDGET_BEGIN_NAMESPACE
|
||||
|
||||
/*!
|
||||
* \~english \class DLineEdit
|
||||
* \~english \brief The DLineEdit class provides a styled QLineEdit.
|
||||
*
|
||||
* \~english DLineEdit has an optional action button (DImageButton) at the right side which can be used
|
||||
* \~english to provide extra user interaction, for example: to change the echo mode of
|
||||
* the line edit.
|
||||
*
|
||||
* \~english Also, DLineEdit can be set on or off alert mode, warning the user of some
|
||||
* errors.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~english \brief DLineEdit::DLineEdit constructs an instance of DLineEdit.
|
||||
* \~english \param parent is passed to QLineEdit constructor.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \class DLineEdit
|
||||
* \~chinese \brief DLineEdit提供了一个修改过的QLineEdit样式
|
||||
*
|
||||
* \~chinese DLineEdit右侧提供了可选的动作按钮,可以使用额外的用户交互,例如: 改变密码显示
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \brief DLineEdit的构造函数
|
||||
*
|
||||
* \~chinese \param parent 调用QLineEdit的构造函数
|
||||
*/
|
||||
DLineEdit::DLineEdit(QWidget *parent)
|
||||
: QLineEdit(parent),
|
||||
DObject(*new DLineEditPrivate(this))
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
d->init();
|
||||
}
|
||||
|
||||
DLineEdit::DLineEdit(DLineEditPrivate &q, QWidget *parent)
|
||||
: QLineEdit(parent),
|
||||
DObject(q)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
d->init();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置是否显示警告
|
||||
*
|
||||
* \~chinese @param isAlert 是否显示警告
|
||||
*/
|
||||
void DLineEdit::setAlert(bool isAlert)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
if (isAlert == d->m_isAlert) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_isAlert = isAlert;
|
||||
|
||||
update();
|
||||
|
||||
Q_EMIT alertChanged(isAlert);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~english\property DLineEdit::alert
|
||||
* \~english \brief This property shows whether the line edit is in alert mode or not.
|
||||
*
|
||||
* There'll be a extra frame colored in orage like color showing if the alert
|
||||
* mode is on, to remind the user that the input is wrong.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \property DLineEdit::alert
|
||||
* \~chinese \brief 该属性会返回当前是否处于警告模式
|
||||
*
|
||||
* 将会有一个警告的颜色在额外的边框上显示,如果警告模式开启,将会提示用户输入错误
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 返回当前是否处于警告模式
|
||||
*
|
||||
* 将会有一个警告的颜色在额外的边框上显示,如果警告模式开启,将会提示用户输入错误
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool DLineEdit::isAlert() const
|
||||
{
|
||||
D_DC(DLineEdit);
|
||||
|
||||
return d->m_isAlert;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置的文本会在警告模式下显示
|
||||
*
|
||||
* @param text 警告的文本
|
||||
* @param duration 显示的时间长度
|
||||
*/
|
||||
void DLineEdit::showAlertMessage(const QString &text, int duration)
|
||||
{
|
||||
D_D(DLineEdit);
|
||||
|
||||
if (!d->tooltip) {
|
||||
d->tooltip = new DArrowRectangle(DArrowRectangle::ArrowTop, this);
|
||||
d->tooltip->setObjectName("AlertTooltip");
|
||||
|
||||
QLabel *label = new QLabel(d->tooltip);
|
||||
|
||||
label->setWordWrap(true);
|
||||
label->setMaximumWidth(width());
|
||||
d->tooltip->setContent(label);
|
||||
d->tooltip->setBackgroundColor(DThemeManager::instance()->theme(this) == "light" ? Qt::white : Qt::black);
|
||||
d->tooltip->setArrowX(15);
|
||||
d->tooltip->setArrowHeight(5);
|
||||
|
||||
QTimer::singleShot(duration, d->tooltip, [d] {
|
||||
d->tooltip->deleteLater();
|
||||
d->tooltip = Q_NULLPTR;
|
||||
});
|
||||
}
|
||||
|
||||
QLabel *label = qobject_cast<QLabel *>(d->tooltip->getContent());
|
||||
|
||||
if (!label) {
|
||||
return;
|
||||
}
|
||||
|
||||
label->setText(text);
|
||||
label->adjustSize();
|
||||
|
||||
const QPoint &pos = mapToGlobal(QPoint(15, height()));
|
||||
|
||||
d->tooltip->show(pos.x(), pos.y());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 隐藏警告的消息框
|
||||
*
|
||||
*/
|
||||
void DLineEdit:: hideAlertMessage()
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
if (d->tooltip) {
|
||||
d->tooltip->hide();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置图标是否可见
|
||||
*
|
||||
* @param visible
|
||||
*/
|
||||
void DLineEdit::setIconVisible(bool visible)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
if (visible == d->m_rightIcon->isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_rightIcon->setVisible(visible);
|
||||
|
||||
if (visible) {
|
||||
|
||||
addAction(d->m_iconAction, TrailingPosition);
|
||||
#ifndef Q_OS_WIN
|
||||
QLineEditPrivate *d_d = reinterpret_cast<QLineEditPrivate*>(d_ptr.data());
|
||||
if (d_d->trailingSideWidgets.size() > 1) {
|
||||
if ((*(d_d->trailingSideWidgets.end() - 1)).action == d->m_iconAction) {
|
||||
d_d->trailingSideWidgets.insert(d_d->trailingSideWidgets.begin(), *d_d->trailingSideWidgets.erase(d_d->trailingSideWidgets.end() - 1));
|
||||
QResizeEvent resize_event(size(), size());
|
||||
qApp->sendEvent(this, &resize_event);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
removeAction(d->m_iconAction);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~english \property DLineEdit::iconVisible
|
||||
* \~english \brief This property holds whether the action button can be seen.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \property DLineEdit::iconVisible
|
||||
* \~chinese 这个属性将会决定动作按钮的图标是否可见
|
||||
*/
|
||||
bool DLineEdit::iconVisible() const
|
||||
{
|
||||
D_DC(DLineEdit);
|
||||
|
||||
return d->m_rightIcon->isVisible();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~english \property DLineEdit::normalIcon
|
||||
* \~english \brief This property holds the image used as the normal state of the action button.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \property DLineEdit::normalIcon
|
||||
* \~chinese 该属性返回normal状态的图标
|
||||
*/
|
||||
QString DLineEdit::normalIcon() const
|
||||
{
|
||||
D_DC(DLineEdit);
|
||||
|
||||
return d->m_rightIcon->getNormalPic();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置normal状态的图标
|
||||
*
|
||||
* @param normalIcon
|
||||
*/
|
||||
void DLineEdit::setNormalIcon(const QString &normalIcon)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
d->m_rightIcon->setNormalPic(normalIcon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~english \property DLineEdit::hoverIcon
|
||||
* \~english \brief This property holds the image used as the hover state of the action button.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \property DLineEdit::hoverIcon
|
||||
* \~chinese 该属性返回鼠标在动作按钮上时,按钮的图标
|
||||
*/
|
||||
QString DLineEdit::hoverIcon() const
|
||||
{
|
||||
D_DC(DLineEdit);
|
||||
|
||||
return d->m_rightIcon->getHoverPic();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置鼠标在动作按钮上时,按钮的图标
|
||||
*
|
||||
* @param hoverIcon 鼠标在动作按钮上时,按钮的图标的路径
|
||||
*/
|
||||
void DLineEdit::setHoverIcon(const QString &hoverIcon)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
d->m_rightIcon->setHoverPic(hoverIcon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~english \property DLineEdit::pressIcon
|
||||
* \~english \brief This property holds the image used as the pressed state of the action button.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \~chinese \property DLineEdit::pressIcon
|
||||
* \~chinese 该属性返回鼠标按下时动作按钮的图标
|
||||
*/
|
||||
QString DLineEdit::pressIcon() const
|
||||
{
|
||||
D_DC(DLineEdit);
|
||||
|
||||
return d->m_rightIcon->getPressPic();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \~chinese \brief 设置鼠标按下时动作按钮的图标
|
||||
*
|
||||
* @param pressIcon 鼠标按下时动作按钮的图标路径
|
||||
*/
|
||||
void DLineEdit::setPressIcon(const QString &pressIcon)
|
||||
{
|
||||
Q_D(DLineEdit);
|
||||
|
||||
d->m_rightIcon->setPressPic(pressIcon);
|
||||
}
|
||||
|
||||
void DLineEdit::focusInEvent(QFocusEvent *e)
|
||||
{
|
||||
Q_EMIT focusChanged(true);
|
||||
QLineEdit::focusInEvent(e);
|
||||
}
|
||||
|
||||
void DLineEdit::focusOutEvent(QFocusEvent *e)
|
||||
{
|
||||
Q_EMIT focusChanged(false);
|
||||
QLineEdit::focusOutEvent(e);
|
||||
}
|
||||
|
||||
void DLineEdit::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QLineEdit::resizeEvent(e);
|
||||
|
||||
Q_EMIT sizeChanged(e->size());
|
||||
|
||||
D_D(DLineEdit);
|
||||
|
||||
d->m_rightIcon->setFixedHeight(e->size().height() - 2);
|
||||
}
|
||||
|
||||
bool DLineEdit::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
D_D(DLineEdit);
|
||||
|
||||
if (watched == d->m_rightIcon) {
|
||||
if (event->type() == QEvent::Move) {
|
||||
d->m_rightIcon->move(width() - d->m_rightIcon->width() - 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DLineEditPrivate::DLineEditPrivate(DLineEdit *q)
|
||||
: DObjectPrivate(q)
|
||||
{
|
||||
}
|
||||
|
||||
void DLineEditPrivate::init()
|
||||
{
|
||||
Q_Q(DLineEdit);
|
||||
m_rightIcon = new DImageButton(q);
|
||||
m_rightIcon->setObjectName("IconButton");
|
||||
m_rightIcon->installEventFilter(q);
|
||||
|
||||
m_iconAction = new QWidgetAction(q);
|
||||
m_iconAction->setDefaultWidget(m_rightIcon);
|
||||
m_rightIcon->hide();
|
||||
|
||||
q->connect(m_rightIcon, &DImageButton::clicked, q, &DLineEdit::iconClicked);
|
||||
}
|
||||
|
||||
DWIDGET_END_NAMESPACE
|
||||
|
||||
#include "moc_dlineedit.cpp"
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DLINEEDIT_H
|
||||
#define DLINEEDIT_H
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "dtkwidget_global.h"
|
||||
#include "dobject.h"
|
||||
|
||||
DWIDGET_BEGIN_NAMESPACE
|
||||
|
||||
class DLineEditPrivate;
|
||||
class DStyleOptionLineEdit;
|
||||
class LIBDTKWIDGETSHARED_EXPORT DLineEdit : public QLineEdit, public DTK_CORE_NAMESPACE::DObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(DLineEdit)
|
||||
D_DECLARE_PRIVATE(DLineEdit)
|
||||
Q_PROPERTY(bool alert READ isAlert WRITE setAlert NOTIFY alertChanged)
|
||||
Q_PROPERTY(QString normalIcon READ normalIcon WRITE setNormalIcon DESIGNABLE true)
|
||||
Q_PROPERTY(QString hoverIcon READ hoverIcon WRITE setHoverIcon DESIGNABLE true)
|
||||
Q_PROPERTY(QString pressIcon READ pressIcon WRITE setPressIcon DESIGNABLE true)
|
||||
Q_PROPERTY(bool iconVisible READ iconVisible WRITE setIconVisible)
|
||||
|
||||
public:
|
||||
DLineEdit(QWidget *parent = 0);
|
||||
|
||||
void setAlert(bool isAlert);
|
||||
bool isAlert() const;
|
||||
void showAlertMessage(const QString &text, int duration = 3000);
|
||||
void hideAlertMessage();
|
||||
|
||||
void setIconVisible(bool visible);
|
||||
bool iconVisible() const;
|
||||
|
||||
QString normalIcon() const;
|
||||
QString hoverIcon() const;
|
||||
QString pressIcon() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setNormalIcon(const QString &normalIcon);
|
||||
void setHoverIcon(const QString &hoverIcon);
|
||||
void setPressIcon(const QString &pressIcon);
|
||||
|
||||
Q_SIGNALS:
|
||||
void iconClicked() const;
|
||||
void alertChanged(bool alert) const;
|
||||
void focusChanged(bool onFocus) const;
|
||||
void sizeChanged(const QSize &size) const;
|
||||
|
||||
protected:
|
||||
DLineEdit(DLineEditPrivate &q, QWidget *parent);
|
||||
|
||||
void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
|
||||
void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
friend class DStyleOptionLineEdit;
|
||||
};
|
||||
|
||||
DWIDGET_END_NAMESPACE
|
||||
|
||||
#endif // DLINEEDIT_H
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "drawthememanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
|
||||
#include "utils/baseutils.h"
|
||||
|
||||
namespace {
|
||||
const QString THEME_GROUP = "APP";
|
||||
const QString THEME_TEXT = "AppTheme";
|
||||
}
|
||||
|
||||
DrawThemeManager * DrawThemeManager::m_drawTheme = NULL;
|
||||
DrawThemeManager *DrawThemeManager::instance()
|
||||
{
|
||||
if (m_drawTheme == NULL) {
|
||||
m_drawTheme = new DrawThemeManager;
|
||||
}
|
||||
|
||||
return m_drawTheme;
|
||||
}
|
||||
|
||||
DrawThemeManager::DrawThemeManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString DrawThemeManager::getCurrentTheme(){
|
||||
return m_currentTheme;
|
||||
}
|
||||
|
||||
void DrawThemeManager::setCurrentTheme(QString themeName) {
|
||||
m_currentTheme = themeName;
|
||||
|
||||
emit themeChanged(m_currentTheme);
|
||||
}
|
||||
|
||||
QString DrawThemeManager::getQssForWidget(QString className) {
|
||||
return getFileContent(QString(":/theme/%1/%2.qss").arg(m_currentTheme).arg(className));
|
||||
}
|
||||
|
||||
void DrawThemeManager::updateQss()
|
||||
{
|
||||
QWidget *w = qobject_cast<QWidget*>(sender());
|
||||
if(w){
|
||||
w->setStyleSheet(w->styleSheet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef DRAWTHEMEMANAGER_H
|
||||
#define DRAWTHEMEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DrawThemeManager : public QObject {
|
||||
Q_OBJECT
|
||||
DrawThemeManager(QObject* parent = 0);
|
||||
public:
|
||||
static DrawThemeManager* instance();
|
||||
|
||||
signals:
|
||||
void themeChanged(QString themeName);
|
||||
|
||||
public slots:
|
||||
QString getCurrentTheme();
|
||||
void setCurrentTheme(QString themeName);
|
||||
QString getQssForWidget(QString className);
|
||||
void updateQss();
|
||||
|
||||
private:
|
||||
static DrawThemeManager* m_drawTheme;
|
||||
QString m_currentTheme = "light";
|
||||
};
|
||||
|
||||
#endif // DRAWTHEMEMANAGER_H
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef FONTSIZELINEEDIT_H
|
||||
#define FONTSIZELINEEDIT_H
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QShortcut>
|
||||
#include <QKeyEvent>
|
||||
#include <QDebug>
|
||||
|
||||
class FontsizeLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FontsizeLineEdit(QWidget* parent = 0) {
|
||||
Q_UNUSED(parent);
|
||||
}
|
||||
~FontsizeLineEdit(){}
|
||||
|
||||
signals:
|
||||
void addSize();
|
||||
void reduceSize();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Up)
|
||||
{
|
||||
emit addSize();
|
||||
} else if (e->key() == Qt::Key_Down)
|
||||
{
|
||||
emit reduceSize();
|
||||
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)
|
||||
{
|
||||
emit editingFinished();
|
||||
}
|
||||
|
||||
QLineEdit::keyPressEvent(e);
|
||||
}
|
||||
|
||||
};
|
||||
#endif // FONTSIZELINEEDIT_H
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "graphicsgloweffect.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
GraphicsGlowEffect::GraphicsGlowEffect(QObject *parent) :
|
||||
QGraphicsEffect(parent),
|
||||
m_xOffset(0),
|
||||
m_yOffset(0),
|
||||
m_distance(4.0f),
|
||||
m_blurRadius(10.0f),
|
||||
m_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 GraphicsGlowEffect::cachePixmap(const QPixmap &sourcePx)
|
||||
{
|
||||
// Calculate size for the background image
|
||||
QSize scaleSize(sourcePx.size().width() + 2 * distance(), sourcePx.size().height() + 2 * distance());
|
||||
|
||||
if (cacheBlurPixmap.size() == scaleSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage tmpImg(scaleSize, QImage::Format_ARGB32_Premultiplied);
|
||||
QPixmap scaled = sourcePx.scaled(scaleSize);
|
||||
tmpImg.fill(0);
|
||||
QPainter tmpPainter(&tmpImg);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled);
|
||||
tmpPainter.end();
|
||||
|
||||
// blur the alpha channel
|
||||
QImage blurred(tmpImg.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
blurred.fill(0);
|
||||
QPainter blurPainter(&blurred);
|
||||
qt_blurImage(&blurPainter, tmpImg, blurRadius(), false, true);
|
||||
blurPainter.end();
|
||||
|
||||
tmpImg = blurred;
|
||||
|
||||
// blacken the image...
|
||||
tmpPainter.begin(&tmpImg);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
tmpPainter.fillRect(tmpImg.rect(), color());
|
||||
tmpPainter.end();
|
||||
|
||||
cacheBlurPixmap = QPixmap::fromImage(tmpImg);
|
||||
}
|
||||
|
||||
void GraphicsGlowEffect::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 sourcePx = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
|
||||
|
||||
// return if no source
|
||||
if (sourcePx.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cachePixmap(sourcePx);
|
||||
|
||||
// save world transform
|
||||
QTransform restoreTransform = painter->worldTransform();
|
||||
painter->setWorldTransform(QTransform());
|
||||
|
||||
// draw the blurred shadow...
|
||||
painter->drawPixmap(offset, cacheBlurPixmap);
|
||||
|
||||
// draw the actual pixmap...
|
||||
painter->drawPixmap(offset, sourcePx, QRectF());
|
||||
|
||||
// restore world transform
|
||||
painter->setWorldTransform(restoreTransform);
|
||||
}
|
||||
|
||||
QRectF GraphicsGlowEffect::boundingRectFor(const QRectF &rect) const
|
||||
{
|
||||
qreal delta = blurRadius() + distance();
|
||||
return rect.united(rect.adjusted(-delta - xOffset(), -delta - yOffset(), delta - xOffset(), delta - yOffset()));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GraphicsGlowEffect_H
|
||||
#define GraphicsGlowEffect_H
|
||||
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QGraphicsEffect>
|
||||
#include <QPainter>
|
||||
|
||||
#include "dtkwidget_global.h"
|
||||
|
||||
DWIDGET_BEGIN_NAMESPACE
|
||||
|
||||
class LIBDTKWIDGETSHARED_EXPORT GraphicsGlowEffect : public QGraphicsEffect
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GraphicsGlowEffect(QObject *parent = 0);
|
||||
|
||||
void draw(QPainter *painter);
|
||||
QRectF boundingRectFor(const QRectF &rect) const;
|
||||
|
||||
inline void setOffset(qreal dx, qreal dy) {m_xOffset = dx; m_yOffset = dy;}
|
||||
|
||||
inline void setXOffset(qreal dx) {m_xOffset = dx;}
|
||||
inline qreal xOffset() const {return m_xOffset;}
|
||||
|
||||
inline void setYOffset(qreal dy) {m_yOffset = dy;}
|
||||
inline qreal yOffset() const {return m_yOffset;}
|
||||
|
||||
inline void setDistance(qreal distance) { m_distance = distance; updateBoundingRect(); }
|
||||
inline qreal distance() const { return m_distance; }
|
||||
|
||||
inline void setBlurRadius(qreal blurRadius) { m_blurRadius = blurRadius; updateBoundingRect(); }
|
||||
inline qreal blurRadius() const { return m_blurRadius; }
|
||||
|
||||
inline void setColor(const QColor &color) { m_color = color; }
|
||||
inline QColor color() const { return m_color; }
|
||||
|
||||
protected:
|
||||
void cachePixmap(const QPixmap &source);
|
||||
|
||||
private:
|
||||
QPixmap cacheBlurPixmap;
|
||||
qreal m_xOffset;
|
||||
qreal m_yOffset;
|
||||
qreal m_distance;
|
||||
qreal m_blurRadius;
|
||||
QColor m_color;
|
||||
};
|
||||
|
||||
DWIDGET_END_NAMESPACE
|
||||
|
||||
#endif // GraphicsGlowEffect_H
|
||||
@@ -0,0 +1,143 @@
|
||||
#include "iconbutton.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
IconButton::IconButton(const QString &normalPic, const QString &hoverPic, const QString
|
||||
&pressPic, const QString &text, QWidget *parent) : QPushButton(parent) {
|
||||
|
||||
setStyleSheet("");
|
||||
if (!normalPic.isEmpty())
|
||||
m_normalPic = normalPic;
|
||||
if (!hoverPic.isEmpty())
|
||||
m_hoverPic = hoverPic;
|
||||
if (!pressPic.isEmpty())
|
||||
m_pressPic = pressPic;
|
||||
|
||||
setText(text);
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
IconButton::IconButton(const QString &normalPic, const QString &hoverPic, const QString
|
||||
&pressPic, const QString &checkedPic, const QString &text, QWidget *parent) : QPushButton(parent) {
|
||||
|
||||
setStyleSheet("QPushButton {outline: none; background-color: transparent; border: none;}");
|
||||
|
||||
if (!normalPic.isEmpty())
|
||||
m_normalPic = normalPic;
|
||||
if (!hoverPic.isEmpty())
|
||||
m_hoverPic = hoverPic;
|
||||
if (!pressPic.isEmpty())
|
||||
m_pressPic = pressPic;
|
||||
if (!checkedPic.isEmpty())
|
||||
m_checkedPic = checkedPic;
|
||||
|
||||
setText(text);
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
IconButton::~IconButton() {}
|
||||
|
||||
void IconButton::setNormalPic(const QString &normalPic) {
|
||||
m_normalPic = normalPic;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void IconButton::setHoverPic(const QString &hoverPic) {
|
||||
m_hoverPic = hoverPic;
|
||||
updateIcon();
|
||||
}
|
||||
void IconButton::setPressPic(const QString &pressPic) {
|
||||
m_pressPic = pressPic;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void IconButton::setCheckedPic(const QString &checkedPic) {
|
||||
m_checkedPic = checkedPic;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
IconButton::State IconButton::getState() const {
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void IconButton::enterEvent(QEvent* event) {
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
if (!isChecked()) {
|
||||
setState(Hover);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void IconButton::leaveEvent(QEvent* event) {
|
||||
if (!isChecked()) {
|
||||
setState(Normal);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void IconButton::mousePressEvent(QMouseEvent* event) {
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCheckable()) {
|
||||
if (isChecked()) {
|
||||
setChecked(false);
|
||||
setState(Press);
|
||||
} else {
|
||||
setChecked(true);
|
||||
setState(Checked);
|
||||
}
|
||||
} else {
|
||||
setState(Press);
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void IconButton::mouseReleaseEvent(QMouseEvent* event) {
|
||||
if (!rect().contains(event->pos())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isCheckable()) {
|
||||
if (isChecked()) {
|
||||
setState(Checked);
|
||||
} else {
|
||||
setState(Normal);
|
||||
}
|
||||
} else {
|
||||
setState(Hover);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
QPushButton::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void IconButton::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (!isCheckable() && !rect().contains(event->pos())) {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
void IconButton::updateIcon() {
|
||||
switch (m_state) {
|
||||
case Hover:{ if (!m_hoverPic.isEmpty()) setIcon(QPixmap(m_hoverPic)); qDebug() << "Hover:" << QPixmap(m_hoverPic).isNull();break;}
|
||||
case Press: if (!m_pressPic.isEmpty()) setIcon(QPixmap(m_pressPic)); qDebug() << "Press:" << QPixmap(m_pressPic).isNull(); break;
|
||||
case Checked: if (!m_checkedPic.isEmpty()) setIcon(QPixmap(m_checkedPic)); qDebug() << "Checked:" << QPixmap(m_checkedPic).isNull(); break;
|
||||
default: if (!m_normalPic.isEmpty()) setIcon(QPixmap(m_normalPic)); break;
|
||||
}
|
||||
|
||||
Q_EMIT stateChanged();
|
||||
}
|
||||
|
||||
void IconButton::setState(State state) {
|
||||
m_state = state;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef ICONBUTTON_H
|
||||
#define ICONBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
class IconButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum State {Normal, Hover, Press, Checked};
|
||||
|
||||
IconButton(const QString &normalPic, const QString &hoverPic,
|
||||
const QString &pressPic, const QString &text, QWidget* parent = 0);
|
||||
IconButton(const QString &normalPic, const QString &hoverPic,
|
||||
const QString &pressPic, const QString &checkedPic, const QString &text, QWidget* parent = 0);
|
||||
~IconButton();
|
||||
|
||||
void setNormalPic(const QString &normalPic);
|
||||
void setHoverPic(const QString &hoverPic);
|
||||
void setPressPic(const QString &pressPic);
|
||||
void setCheckedPic(const QString &checkedPic);
|
||||
|
||||
inline const QString getNormalPic() const { return m_normalPic;}
|
||||
inline const QString getHoverPic() const { return m_hoverPic;}
|
||||
inline const QString getPressPic() const { return m_pressPic;}
|
||||
inline const QString getCheckedPic() const { return m_checkedPic;}
|
||||
|
||||
State getState() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void stateChanged();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent* event) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent* event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void updateIcon();
|
||||
void setState(State state);
|
||||
|
||||
private:
|
||||
State m_state = Normal;
|
||||
|
||||
QString m_normalPic;
|
||||
QString m_hoverPic;
|
||||
QString m_pressPic;
|
||||
QString m_checkedPic;
|
||||
|
||||
};
|
||||
#endif // ICONBUTTON_H
|
||||
@@ -0,0 +1,99 @@
|
||||
#ifndef IMAGECROPPER_H
|
||||
#define IMAGECROPPER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QPainter>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "imagecropperlabel.h"
|
||||
|
||||
/*******************************************************
|
||||
* Loacl private class, which do image-cropping
|
||||
* Used in class ImageCropper
|
||||
*******************************************************/
|
||||
class ImageCropperDialogPrivate : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageCropperDialogPrivate(const QPixmap& imageIn, QPixmap& outputImage,
|
||||
int windowWidth, int windowHeight,
|
||||
CropperShape shape, QSize cropperSize = QSize()) :
|
||||
QDialog(nullptr), outputImage(outputImage)
|
||||
{
|
||||
this->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
this->setWindowTitle("Image Cropper");
|
||||
this->setMouseTracking(true);
|
||||
this->setModal(true);
|
||||
|
||||
imageLabel = new ImageCropperLabel(windowWidth, windowHeight, this);
|
||||
imageLabel->setCropper(shape, cropperSize);
|
||||
imageLabel->setOutputShape(OutputShape::RECT);
|
||||
imageLabel->setOriginalImage(imageIn);
|
||||
imageLabel->enableOpacity(true);
|
||||
|
||||
QHBoxLayout* btnLayout = new QHBoxLayout();
|
||||
btnOk = new QPushButton("OK", this);
|
||||
btnCancel = new QPushButton("Cancel", this);
|
||||
btnLayout->addStretch();
|
||||
btnLayout->addWidget(btnOk);
|
||||
btnLayout->addWidget(btnCancel);
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->addWidget(imageLabel);
|
||||
mainLayout->addLayout(btnLayout);
|
||||
|
||||
connect(btnOk, &QPushButton::clicked, this, [this](){
|
||||
this->outputImage = this->imageLabel->getCroppedImage();
|
||||
this->close();
|
||||
});
|
||||
connect(btnCancel, &QPushButton::clicked, this, [this](){
|
||||
this->outputImage = QPixmap();
|
||||
this->close();
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
ImageCropperLabel* imageLabel;
|
||||
QPushButton* btnOk;
|
||||
QPushButton* btnCancel;
|
||||
QPixmap& outputImage;
|
||||
};
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
* class ImageCropperDialog
|
||||
* create a instane of class ImageCropperDialogPrivate
|
||||
* and get cropped image from the instance(after closing)
|
||||
********************************************************************/
|
||||
class ImageCropperDialog : QObject {
|
||||
public:
|
||||
static QPixmap getCroppedImage(const QString& filename,int windowWidth, int windowHeight,
|
||||
CropperShape cropperShape, QSize crooperSize = QSize())
|
||||
{
|
||||
QPixmap inputImage;
|
||||
QPixmap outputImage;
|
||||
|
||||
if (!inputImage.load(filename)) {
|
||||
QMessageBox::critical(nullptr, "Error", "Load image failed!", QMessageBox::Ok);
|
||||
return outputImage;
|
||||
}
|
||||
|
||||
ImageCropperDialogPrivate* imageCropperDo =
|
||||
new ImageCropperDialogPrivate(inputImage, outputImage,
|
||||
windowWidth, windowHeight,
|
||||
cropperShape, crooperSize);
|
||||
imageCropperDo->exec();
|
||||
|
||||
return outputImage;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // IMAGECROPPER_H
|
||||
@@ -0,0 +1,714 @@
|
||||
#include "imagecropperlabel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QBitmap>
|
||||
|
||||
ImageCropperLabel::ImageCropperLabel(int width, int height, QWidget* parent) :
|
||||
QLabel(parent)
|
||||
{
|
||||
this->setFixedSize(width, height);
|
||||
this->setAlignment(Qt::AlignCenter);
|
||||
this->setMouseTracking(true);
|
||||
|
||||
borderPen.setWidth(1);
|
||||
borderPen.setColor(Qt::white);
|
||||
borderPen.setDashPattern(QVector<qreal>() << 3 << 3 << 3 << 3);
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setOriginalImage(const QPixmap &pixmap) {
|
||||
originalImage = pixmap;
|
||||
|
||||
int imgWidth = pixmap.width();
|
||||
int imgHeight = pixmap.height();
|
||||
int labelWidth = this->width();
|
||||
int labelHeight = this->height();
|
||||
int imgWidthInLabel;
|
||||
int imgHeightInLabel;
|
||||
|
||||
if (imgWidth * labelHeight < imgHeight * labelWidth) {
|
||||
scaledRate = labelHeight / double(imgHeight);
|
||||
imgHeightInLabel = labelHeight;
|
||||
imgWidthInLabel = int(scaledRate * imgWidth);
|
||||
imageRect.setRect((labelWidth - imgWidthInLabel) / 2, 0,
|
||||
imgWidthInLabel, imgHeightInLabel);
|
||||
}
|
||||
else {
|
||||
scaledRate = labelWidth / double(imgWidth);
|
||||
imgWidthInLabel = labelWidth;
|
||||
imgHeightInLabel = int(scaledRate * imgHeight);
|
||||
imageRect.setRect(0, (labelHeight - imgHeightInLabel) / 2,
|
||||
imgWidthInLabel, imgHeightInLabel);
|
||||
}
|
||||
|
||||
tempImage = originalImage.scaled(imgWidthInLabel, imgHeightInLabel,
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
this->setPixmap(tempImage);
|
||||
|
||||
if (cropperShape >= CropperShape::FIXED_RECT) {
|
||||
cropperRect.setWidth(int(cropperRect_.width() * scaledRate));
|
||||
cropperRect.setHeight(int(cropperRect_.height() * scaledRate));
|
||||
}
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************
|
||||
* set cropper's shape (and size)
|
||||
*****************************************/
|
||||
void ImageCropperLabel::setRectCropper() {
|
||||
cropperShape = CropperShape::RECT;
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setSquareCropper() {
|
||||
cropperShape = CropperShape::SQUARE;
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setEllipseCropper() {
|
||||
cropperShape = CropperShape::ELLIPSE;
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setCircleCropper() {
|
||||
cropperShape = CropperShape::CIRCLE;
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setFixedRectCropper(QSize size) {
|
||||
cropperShape = CropperShape::FIXED_RECT;
|
||||
cropperRect_.setSize(size);
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setFixedEllipseCropper(QSize size) {
|
||||
cropperShape = CropperShape::FIXED_ELLIPSE;
|
||||
cropperRect_.setSize(size);
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
// not recommended
|
||||
void ImageCropperLabel::setCropper(CropperShape shape, QSize size) {
|
||||
cropperShape = shape;
|
||||
cropperRect_.setSize(size);
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Set cropper's fixed size
|
||||
*****************************************************************************/
|
||||
void ImageCropperLabel::setCropperFixedSize(int fixedWidth, int fixedHeight) {
|
||||
cropperRect_.setSize(QSize(fixedWidth, fixedHeight));
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setCropperFixedWidth(int fixedWidth) {
|
||||
cropperRect_.setWidth(fixedWidth);
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::setCropperFixedHeight(int fixedHeight) {
|
||||
cropperRect_.setHeight(fixedHeight);
|
||||
resetCropperPos();
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
* Move cropper to the center of the image
|
||||
* And resize to default
|
||||
**********************************************/
|
||||
void ImageCropperLabel::resetCropperPos() {
|
||||
int labelWidth = this->width();
|
||||
int labelHeight = this->height();
|
||||
|
||||
if (cropperShape == CropperShape::FIXED_RECT || cropperShape == CropperShape::FIXED_ELLIPSE) {
|
||||
cropperRect.setWidth(int(cropperRect_.width() * scaledRate));
|
||||
cropperRect.setHeight(int(cropperRect_.height() * scaledRate));
|
||||
}
|
||||
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
break;
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE: {
|
||||
cropperRect.setRect((labelWidth - cropperRect.width()) / 2,
|
||||
(labelHeight - cropperRect.height()) / 2,
|
||||
cropperRect.width(), cropperRect.height());
|
||||
break;
|
||||
}
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::ELLIPSE:
|
||||
case CropperShape::CIRCLE: {
|
||||
int imgWidth = tempImage.width();
|
||||
int imgHeight = tempImage.height();
|
||||
int edge = int((imgWidth > imgHeight ? imgHeight : imgWidth) * 3 / 4.0);
|
||||
cropperRect.setRect((labelWidth - edge) / 2, (labelHeight - edge) / 2, edge, edge);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap ImageCropperLabel::getCroppedImage() {
|
||||
return getCroppedImage(this->outputShape);
|
||||
}
|
||||
|
||||
QPixmap ImageCropperLabel::getCroppedImage(OutputShape shape) {
|
||||
int startX = int((cropperRect.left() - imageRect.left()) / scaledRate);
|
||||
int startY = int((cropperRect.top() - imageRect.top()) / scaledRate);
|
||||
int croppedWidth = int(cropperRect.width() / scaledRate);
|
||||
int croppedHeight = int(cropperRect.height() / scaledRate);
|
||||
|
||||
QPixmap resultImage(croppedWidth, croppedHeight);
|
||||
resultImage = originalImage.copy(startX, startY, croppedWidth, croppedHeight);
|
||||
|
||||
// Set ellipse mask (cut to ellipse shape)
|
||||
if (shape == OutputShape::ELLIPSE) {
|
||||
QSize size(croppedWidth, croppedHeight);
|
||||
QBitmap mask(size);
|
||||
QPainter painter(&mask);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.fillRect(0, 0, size.width(), size.height(), Qt::white);
|
||||
painter.setBrush(QColor(0, 0, 0));
|
||||
painter.drawRoundRect(0, 0, size.width(), size.height(), 99, 99);
|
||||
resultImage.setMask(mask);
|
||||
}
|
||||
|
||||
return resultImage;
|
||||
}
|
||||
|
||||
|
||||
void ImageCropperLabel::paintEvent(QPaintEvent *event) {
|
||||
// Draw original image
|
||||
QLabel::paintEvent(event);
|
||||
|
||||
// Draw cropper and set some effects
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
break;
|
||||
case CropperShape::FIXED_RECT:
|
||||
drawRectOpacity();
|
||||
break;
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
drawEllipseOpacity();
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
drawRectOpacity();
|
||||
drawSquareEdge(!ONLY_FOUR_CORNERS);
|
||||
break;
|
||||
case CropperShape::SQUARE:
|
||||
drawRectOpacity();
|
||||
drawSquareEdge(ONLY_FOUR_CORNERS);
|
||||
break;
|
||||
case CropperShape::ELLIPSE:
|
||||
drawEllipseOpacity();
|
||||
drawSquareEdge(!ONLY_FOUR_CORNERS);
|
||||
break;
|
||||
case CropperShape::CIRCLE:
|
||||
drawEllipseOpacity();
|
||||
drawSquareEdge(ONLY_FOUR_CORNERS);
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw cropper rect
|
||||
if (isShowRectBorder) {
|
||||
QPainter painter(this);
|
||||
painter.setPen(borderPen);
|
||||
painter.drawRect(cropperRect);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageCropperLabel::drawSquareEdge(bool onlyFourCorners) {
|
||||
if (!isShowDragSquare)
|
||||
return;
|
||||
|
||||
// Four corners
|
||||
drawFillRect(cropperRect.topLeft(), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(cropperRect.topRight(), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(cropperRect.bottomLeft(), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(cropperRect.bottomRight(), dragSquareEdge, dragSquareColor);
|
||||
|
||||
// Four edges
|
||||
if (!onlyFourCorners) {
|
||||
int centralX = cropperRect.left() + cropperRect.width() / 2;
|
||||
int centralY = cropperRect.top() + cropperRect.height() / 2;
|
||||
drawFillRect(QPoint(cropperRect.left(), centralY), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(QPoint(centralX, cropperRect.top()), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(QPoint(cropperRect.right(), centralY), dragSquareEdge, dragSquareColor);
|
||||
drawFillRect(QPoint(centralX, cropperRect.bottom()), dragSquareEdge, dragSquareColor);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageCropperLabel::drawFillRect(QPoint centralPoint, int edge, QColor color) {
|
||||
QRect rect(centralPoint.x() - edge / 2, centralPoint.y() - edge / 2, edge, edge);
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect, color);
|
||||
}
|
||||
|
||||
// Opacity effect
|
||||
void ImageCropperLabel::drawOpacity(const QPainterPath& path) {
|
||||
QPainter painterOpac(this);
|
||||
painterOpac.setOpacity(opacity);
|
||||
painterOpac.fillPath(path, QBrush(Qt::black));
|
||||
}
|
||||
|
||||
void ImageCropperLabel::drawRectOpacity() {
|
||||
if (isShowOpacityEffect) {
|
||||
QPainterPath p1, p2, p;
|
||||
p1.addRect(imageRect);
|
||||
p2.addRect(cropperRect);
|
||||
p = p1.subtracted(p2);
|
||||
drawOpacity(p);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageCropperLabel::drawEllipseOpacity() {
|
||||
if (isShowOpacityEffect) {
|
||||
QPainterPath p1, p2, p;
|
||||
p1.addRect(imageRect);
|
||||
p2.addEllipse(cropperRect);
|
||||
p = p1.subtracted(p2);
|
||||
drawOpacity(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageCropperLabel::isPosNearDragSquare(const QPoint& pt1, const QPoint& pt2) {
|
||||
return abs(pt1.x() - pt2.x()) * 2 <= dragSquareEdge
|
||||
&& abs(pt1.y() - pt2.y()) * 2 <= dragSquareEdge;
|
||||
}
|
||||
|
||||
int ImageCropperLabel::getPosInCropperRect(const QPoint &pt) {
|
||||
if (isPosNearDragSquare(pt, QPoint(cropperRect.right(), cropperRect.center().y())))
|
||||
return RECT_RIGHT;
|
||||
if (isPosNearDragSquare(pt, cropperRect.bottomRight()))
|
||||
return RECT_BOTTOM_RIGHT;
|
||||
if (isPosNearDragSquare(pt, QPoint(cropperRect.center().x(), cropperRect.bottom())))
|
||||
return RECT_BOTTOM;
|
||||
if (isPosNearDragSquare(pt, cropperRect.bottomLeft()))
|
||||
return RECT_BOTTOM_LEFT;
|
||||
if (isPosNearDragSquare(pt, QPoint(cropperRect.left(), cropperRect.center().y())))
|
||||
return RECT_LEFT;
|
||||
if (isPosNearDragSquare(pt, cropperRect.topLeft()))
|
||||
return RECT_TOP_LEFT;
|
||||
if (isPosNearDragSquare(pt, QPoint(cropperRect.center().x(), cropperRect.top())))
|
||||
return RECT_TOP;
|
||||
if (isPosNearDragSquare(pt, cropperRect.topRight()))
|
||||
return RECT_TOP_RIGHT;
|
||||
if (cropperRect.contains(pt, true))
|
||||
return RECT_INSIDE;
|
||||
return RECT_OUTSIZD;
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
*
|
||||
* Change mouse cursor type
|
||||
* Arrow, SizeHor, SizeVer, etc...
|
||||
*
|
||||
*************************************************/
|
||||
|
||||
void ImageCropperLabel::changeCursor() {
|
||||
switch (cursorPosInCropperRect) {
|
||||
case RECT_OUTSIZD:
|
||||
setCursor(Qt::ArrowCursor);
|
||||
break;
|
||||
case RECT_BOTTOM_RIGHT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_RIGHT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_BOTTOM: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_BOTTOM_LEFT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
setCursor(Qt::SizeBDiagCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_LEFT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP_LEFT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP_RIGHT: {
|
||||
switch (cropperShape) {
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeBDiagCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_INSIDE: {
|
||||
setCursor(Qt::SizeAllCursor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* Mouse Events
|
||||
*
|
||||
*****************************************************/
|
||||
|
||||
void ImageCropperLabel::mousePressEvent(QMouseEvent *e) {
|
||||
currPos = lastPos = e->pos();
|
||||
isLButtonPressed = true;
|
||||
}
|
||||
|
||||
void ImageCropperLabel::mouseMoveEvent(QMouseEvent *e) {
|
||||
currPos = e->pos();
|
||||
if (!isCursorPosCalculated) {
|
||||
cursorPosInCropperRect = getPosInCropperRect(currPos);
|
||||
changeCursor();
|
||||
}
|
||||
|
||||
if (!isLButtonPressed)
|
||||
return;
|
||||
if (!imageRect.contains(currPos))
|
||||
return;
|
||||
|
||||
isCursorPosCalculated = true;
|
||||
|
||||
int xOffset = currPos.x() - lastPos.x();
|
||||
int yOffset = currPos.y() - lastPos.y();
|
||||
lastPos = currPos;
|
||||
|
||||
int disX = 0;
|
||||
int disY = 0;
|
||||
|
||||
// Move cropper
|
||||
switch (cursorPosInCropperRect) {
|
||||
case RECT_OUTSIZD:
|
||||
break;
|
||||
case RECT_BOTTOM_RIGHT: {
|
||||
disX = currPos.x() - cropperRect.left();
|
||||
disY = currPos.y() - cropperRect.top();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
break;
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
if (disX >= cropperMinimumWidth && disY >= cropperMinimumHeight) {
|
||||
if (disX > disY && cropperRect.top() + disX <= imageRect.bottom()) {
|
||||
cropperRect.setRight(currPos.x());
|
||||
cropperRect.setBottom(cropperRect.top() + disX);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
else if (disX <= disY && cropperRect.left() + disY <= imageRect.right()) {
|
||||
cropperRect.setBottom(currPos.y());
|
||||
cropperRect.setRight(cropperRect.left() + disY);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
if (disX >= cropperMinimumWidth) {
|
||||
cropperRect.setRight(currPos.x());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setBottom(currPos.y());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_RIGHT: {
|
||||
disX = currPos.x() - cropperRect.left();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disX >= cropperMinimumWidth) {
|
||||
cropperRect.setRight(currPos.x());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_BOTTOM: {
|
||||
disY = currPos.y() - cropperRect.top();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setBottom(cropperRect.bottom() + yOffset);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_BOTTOM_LEFT: {
|
||||
disX = cropperRect.right() - currPos.x();
|
||||
disY = currPos.y() - cropperRect.top();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
break;
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disX >= cropperMinimumWidth) {
|
||||
cropperRect.setLeft(currPos.x());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setBottom(currPos.y());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
if (disX >= cropperMinimumWidth && disY >= cropperMinimumHeight) {
|
||||
if (disX > disY && cropperRect.top() + disX <= imageRect.bottom()) {
|
||||
cropperRect.setLeft(currPos.x());
|
||||
cropperRect.setBottom(cropperRect.top() + disX);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
else if (disX <= disY && cropperRect.right() - disY >= imageRect.left()) {
|
||||
cropperRect.setBottom(currPos.y());
|
||||
cropperRect.setLeft(cropperRect.right() - disY);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_LEFT: {
|
||||
disX = cropperRect.right() - currPos.x();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disX >= cropperMinimumHeight) {
|
||||
cropperRect.setLeft(cropperRect.left() + xOffset);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP_LEFT: {
|
||||
disX = cropperRect.right() - currPos.x();
|
||||
disY = cropperRect.bottom() - currPos.y();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disX >= cropperMinimumWidth) {
|
||||
cropperRect.setLeft(currPos.x());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setTop(currPos.y());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
if (disX >= cropperMinimumWidth && disY >= cropperMinimumHeight) {
|
||||
if (disX > disY && cropperRect.bottom() - disX >= imageRect.top()) {
|
||||
cropperRect.setLeft(currPos.x());
|
||||
cropperRect.setTop(cropperRect.bottom() - disX);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
else if (disX <= disY && cropperRect.right() - disY >= imageRect.left()) {
|
||||
cropperRect.setTop(currPos.y());
|
||||
cropperRect.setLeft(cropperRect.right() - disY);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP: {
|
||||
disY = cropperRect.bottom() - currPos.y();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setTop(cropperRect.top() + yOffset);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_TOP_RIGHT: {
|
||||
disX = currPos.x() - cropperRect.left();
|
||||
disY = cropperRect.bottom() - currPos.y();
|
||||
switch (cropperShape) {
|
||||
case CropperShape::UNDEFINED:
|
||||
case CropperShape::FIXED_RECT:
|
||||
case CropperShape::FIXED_ELLIPSE:
|
||||
break;
|
||||
case CropperShape::RECT:
|
||||
case CropperShape::ELLIPSE:
|
||||
if (disX >= cropperMinimumWidth) {
|
||||
cropperRect.setRight(currPos.x());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
if (disY >= cropperMinimumHeight) {
|
||||
cropperRect.setTop(currPos.y());
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
case CropperShape::SQUARE:
|
||||
case CropperShape::CIRCLE:
|
||||
if (disX >= cropperMinimumWidth && disY >= cropperMinimumHeight) {
|
||||
if (disX < disY && cropperRect.left() + disY <= imageRect.right()) {
|
||||
cropperRect.setTop(currPos.y());
|
||||
cropperRect.setRight(cropperRect.left() + disY);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
else if (disX >= disY && cropperRect.bottom() - disX >= imageRect.top()) {
|
||||
cropperRect.setRight(currPos.x());
|
||||
cropperRect.setTop(cropperRect.bottom() - disX);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RECT_INSIDE: {
|
||||
// Make sure the cropperRect is entirely inside the imageRecct
|
||||
if (xOffset > 0) {
|
||||
if (cropperRect.right() + xOffset > imageRect.right())
|
||||
xOffset = 0;
|
||||
}
|
||||
else if (xOffset < 0) {
|
||||
if (cropperRect.left() + xOffset < imageRect.left())
|
||||
xOffset = 0;
|
||||
}
|
||||
if (yOffset > 0) {
|
||||
if (cropperRect.bottom() + yOffset > imageRect.bottom())
|
||||
yOffset = 0;
|
||||
}
|
||||
else if (yOffset < 0) {
|
||||
if (cropperRect.top() + yOffset < imageRect.top())
|
||||
yOffset = 0;
|
||||
}
|
||||
cropperRect.moveTo(cropperRect.left() + xOffset, cropperRect.top() + yOffset);
|
||||
emit croppedImageChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
void ImageCropperLabel::mouseReleaseEvent(QMouseEvent *) {
|
||||
isLButtonPressed = false;
|
||||
isCursorPosCalculated = false;
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/*************************************************************************
|
||||
* class: ImageCropperLabel
|
||||
* author: github@Leopard-C
|
||||
* email: leopard.c@outlook.com
|
||||
* last change: 2020-03-06
|
||||
*************************************************************************/
|
||||
#ifndef IMAGECROPPERLABEL_H
|
||||
#define IMAGECROPPERLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QPen>
|
||||
|
||||
enum class CropperShape {
|
||||
UNDEFINED = 0,
|
||||
RECT = 1,
|
||||
SQUARE = 2,
|
||||
FIXED_RECT = 3,
|
||||
ELLIPSE = 4,
|
||||
CIRCLE = 5,
|
||||
FIXED_ELLIPSE = 6
|
||||
};
|
||||
|
||||
enum class OutputShape {
|
||||
RECT = 0,
|
||||
ELLIPSE = 1
|
||||
};
|
||||
|
||||
enum class SizeType {
|
||||
fixedSize = 0,
|
||||
fitToMaxWidth = 1,
|
||||
fitToMaxHeight = 2,
|
||||
fitToMaxWidthHeight = 3,
|
||||
};
|
||||
|
||||
|
||||
class ImageCropperLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageCropperLabel(int width, int height, QWidget* parent);
|
||||
|
||||
void setOriginalImage(const QPixmap& pixmap);
|
||||
void setOutputShape(OutputShape shape) { outputShape = shape; }
|
||||
QPixmap getCroppedImage();
|
||||
QPixmap getCroppedImage(OutputShape shape);
|
||||
|
||||
/*****************************************
|
||||
* Set cropper's shape
|
||||
*****************************************/
|
||||
void setRectCropper();
|
||||
void setSquareCropper();
|
||||
void setEllipseCropper();
|
||||
void setCircleCropper();
|
||||
void setFixedRectCropper(QSize size);
|
||||
void setFixedEllipseCropper(QSize size);
|
||||
void setCropper(CropperShape shape, QSize size); // not recommended
|
||||
|
||||
/*****************************************************************************
|
||||
* Set cropper's fixed size
|
||||
*****************************************************************************/
|
||||
void setCropperFixedSize(int fixedWidth, int fixedHeight);
|
||||
void setCropperFixedWidth(int fixedWidht);
|
||||
void setCropperFixedHeight(int fixedHeight);
|
||||
|
||||
/*****************************************************************************
|
||||
* Set cropper's minimum size
|
||||
* default: the twice of minimum of the edge lenght of drag square
|
||||
*****************************************************************************/
|
||||
void setCropperMinimumSize(int minWidth, int minHeight)
|
||||
{ cropperMinimumWidth = minWidth; cropperMinimumHeight = minHeight; }
|
||||
void setCropperMinimumWidth(int minWidth) { cropperMinimumWidth = minWidth; }
|
||||
void setCropperMinimumHeight(int minHeight) { cropperMinimumHeight = minHeight; }
|
||||
|
||||
/*************************************************
|
||||
* Set the size, color, visibility of rectangular border
|
||||
*************************************************/
|
||||
void setShowRectBorder(bool show) { isShowRectBorder = show; }
|
||||
QPen getBorderPen() { return borderPen; }
|
||||
void setBorderPen(const QPen& pen) { borderPen = pen; }
|
||||
|
||||
/*************************************************
|
||||
* Set the size, color of drag square
|
||||
*************************************************/
|
||||
void setShowDragSquare(bool show) { isShowDragSquare = show; }
|
||||
void setDragSquareEdge(int edge) { dragSquareEdge = (edge >= 3 ? edge : 3); }
|
||||
void setDragSquareColor(const QColor& color) { dragSquareColor = color; }
|
||||
|
||||
/*****************************************
|
||||
* Opacity Effect
|
||||
*****************************************/
|
||||
void enableOpacity(bool b = true) { isShowOpacityEffect = b; }
|
||||
void setOpacity(double newOpacity) { opacity = newOpacity; }
|
||||
|
||||
signals:
|
||||
void croppedImageChanged();
|
||||
|
||||
protected:
|
||||
/*****************************************
|
||||
* Event
|
||||
*****************************************/
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
virtual void mousePressEvent(QMouseEvent *e) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *e) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
private:
|
||||
/***************************************
|
||||
* Draw shapes
|
||||
***************************************/
|
||||
void drawFillRect(QPoint centralPoint, int edge, QColor color);
|
||||
void drawRectOpacity();
|
||||
void drawEllipseOpacity();
|
||||
void drawOpacity(const QPainterPath& path); // shadow effect
|
||||
void drawSquareEdge(bool onlyFourCorners);
|
||||
|
||||
/***************************************
|
||||
* Other utility methods
|
||||
***************************************/
|
||||
int getPosInCropperRect(const QPoint& pt);
|
||||
bool isPosNearDragSquare(const QPoint& pt1, const QPoint& pt2);
|
||||
void resetCropperPos();
|
||||
void changeCursor();
|
||||
|
||||
enum {
|
||||
RECT_OUTSIZD = 0,
|
||||
RECT_INSIDE = 1,
|
||||
RECT_TOP_LEFT, RECT_TOP, RECT_TOP_RIGHT, RECT_RIGHT,
|
||||
RECT_BOTTOM_RIGHT, RECT_BOTTOM, RECT_BOTTOM_LEFT, RECT_LEFT
|
||||
};
|
||||
|
||||
const bool ONLY_FOUR_CORNERS = true;
|
||||
|
||||
private:
|
||||
QPixmap originalImage;
|
||||
QPixmap tempImage;
|
||||
|
||||
bool isShowRectBorder = true;
|
||||
QPen borderPen;
|
||||
|
||||
CropperShape cropperShape = CropperShape::UNDEFINED;
|
||||
OutputShape outputShape = OutputShape::RECT;
|
||||
|
||||
QRect imageRect; // the whole image area in the label (not real size)
|
||||
QRect cropperRect; // a rectangle frame to choose image area (not real size)
|
||||
QRect cropperRect_; // cropper rect (real size)
|
||||
double scaledRate = 1.0;
|
||||
|
||||
bool isLButtonPressed = false;
|
||||
bool isCursorPosCalculated = false;
|
||||
int cursorPosInCropperRect = RECT_OUTSIZD;
|
||||
QPoint lastPos;
|
||||
QPoint currPos;
|
||||
|
||||
bool isShowDragSquare = true;
|
||||
int dragSquareEdge = 8;
|
||||
QColor dragSquareColor = Qt::white;
|
||||
|
||||
int cropperMinimumWidth = dragSquareEdge * 2;
|
||||
int cropperMinimumHeight = dragSquareEdge * 2;
|
||||
|
||||
bool isShowOpacityEffect = false;
|
||||
double opacity = 0.6;
|
||||
};
|
||||
|
||||
#endif // IMAGECROPPERLABEL_H
|
||||
@@ -0,0 +1,180 @@
|
||||
#include "lineedittag.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QPainterPath>
|
||||
|
||||
LineEditTag::LineEditTag(QWidget *parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
setMinimumHeight(24);
|
||||
}
|
||||
|
||||
LineEditTag::~LineEditTag()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QStringList LineEditTag::getTags() const
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
QString LineEditTag::getTagsStr() const
|
||||
{
|
||||
return tags.join(' ');
|
||||
}
|
||||
|
||||
void LineEditTag::setTags(const QString& tags)
|
||||
{
|
||||
if (!tags.isEmpty())
|
||||
{
|
||||
this->tags = tags.split(' ');
|
||||
clear();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEditTag::setTags(const QStringList& tags)
|
||||
{
|
||||
if (!tags.isEmpty())
|
||||
{
|
||||
this->tags = tags;
|
||||
clear();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEditTag::addTag()
|
||||
{
|
||||
if (!text().isEmpty())
|
||||
{
|
||||
tags.append(text());
|
||||
clear();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEditTag::leaveEvent(QEvent *evt)
|
||||
{
|
||||
QLineEdit::leaveEvent(evt);
|
||||
cursorPos = clickedPos = QPoint();
|
||||
}
|
||||
|
||||
void LineEditTag::keyPressEvent(QKeyEvent *evt)
|
||||
{
|
||||
if (evt->key() == Qt::Key_Return || evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Space)
|
||||
{
|
||||
evt->accept();
|
||||
addTag();
|
||||
}
|
||||
else
|
||||
{
|
||||
QLineEdit::keyPressEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
void LineEditTag::mousePressEvent(QMouseEvent *evt)
|
||||
{
|
||||
clickedPos = evt->pos();
|
||||
QLineEdit::mousePressEvent(evt);
|
||||
}
|
||||
|
||||
void LineEditTag::mouseMoveEvent(QMouseEvent *evt)
|
||||
{
|
||||
QLineEdit::mouseMoveEvent(evt);
|
||||
cursorPos = evt->pos();
|
||||
}
|
||||
|
||||
void LineEditTag::paintEvent(QPaintEvent *evt)
|
||||
{
|
||||
QLineEdit::paintEvent(evt);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QFontMetrics fm = fontMetrics();
|
||||
QRectF r = rect();
|
||||
double space = double(r.height()-fm.height())/2;
|
||||
int padding = 4;
|
||||
int cross_size = int(r.height()-space*2);
|
||||
r.setX(padding);
|
||||
r.setY(double(r.height()-fm.height())/4);
|
||||
QPen pen = painter.pen();
|
||||
QBrush brush = painter.brush();
|
||||
// Stackoverflow tag like
|
||||
QColor tag_bg(225, 236, 244);
|
||||
QColor tag_txt(44, 87, 119);
|
||||
int x_offset = padding;
|
||||
int idx = 0;
|
||||
for (const QString& tag : tags)
|
||||
{
|
||||
QRect tag_rect = fm.boundingRect(tag);
|
||||
r.setWidth(tag_rect.width()+(padding*2)+(padding+cross_size));
|
||||
r.setHeight(tag_rect.height()+space);
|
||||
QRectF cross_rect = QRectF(r.x()+r.width()-cross_size-padding, space, cross_size, cross_size);
|
||||
if (cross_rect.contains(clickedPos))
|
||||
{
|
||||
clickedPos = QPoint();
|
||||
tags.removeAt(idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPainterPath tag_path;
|
||||
tag_path.addRoundedRect(r, 2, 2);
|
||||
// Draw tag background and text
|
||||
painter.fillPath(tag_path, QBrush(tag_bg));
|
||||
painter.setPen(tag_txt);
|
||||
painter.drawText(QRectF(r.x()+padding, 0, tag_rect.width(), height()), Qt::AlignVCenter, tag);
|
||||
// Draw the cross to remove tag
|
||||
bool isHovered = r.contains(cursorPos);
|
||||
if (isHovered)
|
||||
{
|
||||
// Manage the hovered
|
||||
QPainterPath cross_path;
|
||||
cross_path.addRoundedRect(cross_rect, 2, 2);
|
||||
painter.fillPath(cross_path, QBrush(tag_txt));
|
||||
// Manage the remove tag mouse cursor
|
||||
if (cross_rect.contains(cursorPos))
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
else
|
||||
{
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
pen.setWidth(2);
|
||||
pen.setColor( (isHovered ? tag_bg : tag_txt) );
|
||||
painter.setPen(pen);
|
||||
QPointF topL = cross_rect.topLeft(), topR = cross_rect.topRight(), botL = cross_rect.bottomLeft(), botR = cross_rect.bottomRight();
|
||||
topL.setX(topL.x()+3);
|
||||
topL.setY(topL.y()+3);
|
||||
topR.setX(topR.x()-3);
|
||||
topR.setY(topR.y()+3);
|
||||
botL.setX(botL.x()+3);
|
||||
botL.setY(botL.y()-3);
|
||||
botR.setX(botR.x()-3);
|
||||
botR.setY(botR.y()-3);
|
||||
painter.drawLine(topL, botR);
|
||||
painter.drawLine(topR, botL);
|
||||
|
||||
x_offset += r.width()+(padding);
|
||||
r.setX(x_offset);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (textMargins().left() != (x_offset))
|
||||
{
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
setTextMargins(0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTextMargins(x_offset-padding, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef LINEEDITTAG_H
|
||||
#define LINEEDITTAG_H
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
/**
|
||||
* @author thibsc
|
||||
* @brief The LineEditTag class
|
||||
*/
|
||||
class LineEditTag : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString tags READ getTagsStr WRITE setTags)
|
||||
|
||||
public:
|
||||
explicit LineEditTag(QWidget *parent = nullptr);
|
||||
~LineEditTag() override;
|
||||
QStringList getTags() const;
|
||||
QString getTagsStr() const;
|
||||
void setTags(const QString& tags);
|
||||
void setTags(const QStringList& tags);
|
||||
|
||||
private slots:
|
||||
void addTag();
|
||||
|
||||
protected:
|
||||
void leaveEvent(QEvent *evt) override;
|
||||
void keyPressEvent(QKeyEvent *evt) override;
|
||||
void mousePressEvent(QMouseEvent *evt) override;
|
||||
void mouseMoveEvent(QMouseEvent *evt) override;
|
||||
void paintEvent(QPaintEvent *evt) override;
|
||||
|
||||
private:
|
||||
QStringList tags;
|
||||
QPoint cursorPos, clickedPos;
|
||||
|
||||
};
|
||||
|
||||
#endif // LINEEDITTAG_H
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "loadtips.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include "utils/global.h"
|
||||
|
||||
const QSize TIPS_SIZE = QSize(300, 300);
|
||||
|
||||
LoadTips::LoadTips(QWidget *parent)
|
||||
: QDialog(parent),
|
||||
m_counts(0)
|
||||
{
|
||||
DRAW_THEME_INIT_WIDGET("LoadTips");
|
||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
setModal(true);
|
||||
QLabel* w = new QLabel(this);
|
||||
w->setObjectName("TipsLabel");
|
||||
w->setFixedSize(TIPS_SIZE);
|
||||
m_waterProg = new DWaterProgress(this);
|
||||
m_waterProg->setFixedSize(QSize(200, 200));
|
||||
|
||||
m_messageLabel = new QLabel(this);
|
||||
m_messageLabel->setObjectName("MessageLabel");
|
||||
m_messageLabel->setText(tr("Importing pictures, please wait..."));
|
||||
|
||||
QVBoxLayout* vLayout = new QVBoxLayout(w);
|
||||
vLayout->setMargin(0);
|
||||
vLayout->setSpacing(0);
|
||||
vLayout->addStretch();
|
||||
vLayout->addWidget(m_waterProg, 0, Qt::AlignCenter);
|
||||
vLayout->addSpacing(20);
|
||||
vLayout->addWidget(m_messageLabel, 0, Qt::AlignCenter);
|
||||
vLayout->addStretch();
|
||||
|
||||
connect(this, &LoadTips::progressValueChanged, this, [=](int value){
|
||||
m_counts = value;
|
||||
m_waterProg->setValue(m_counts);
|
||||
});
|
||||
connect(this, &LoadTips::finishedPainting, this, [=]{
|
||||
this->hide();
|
||||
});
|
||||
}
|
||||
|
||||
void LoadTips::showTips()
|
||||
{
|
||||
this->show();
|
||||
QPoint gp = this->mapToGlobal(QPoint(0, 0));
|
||||
move((window()->width() - this->width()) / 2 + gp.x(),
|
||||
(window()->height() - this->height()) / 2 + gp.y());
|
||||
|
||||
|
||||
m_waterProg->setValue(m_counts);
|
||||
m_waterProg->start();
|
||||
|
||||
}
|
||||
|
||||
LoadTips::~LoadTips()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef LOADTIPS_H
|
||||
#define LOADTIPS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <DWaterProgress>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class LoadTips : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LoadTips(QWidget* parent = 0);
|
||||
~LoadTips();
|
||||
|
||||
public:
|
||||
void showTips();
|
||||
|
||||
signals:
|
||||
void progressValueChanged(int value);
|
||||
void finishedPainting();
|
||||
|
||||
private:
|
||||
DWaterProgress* m_waterProg;
|
||||
QLabel* m_messageLabel;
|
||||
int m_counts;
|
||||
};
|
||||
#endif // LOADTIPS_H
|
||||
@@ -0,0 +1,376 @@
|
||||
#include "maillist.h"
|
||||
|
||||
#include <QPen>
|
||||
#include <QHeaderView>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
MailListItemDelegate::MailListItemDelegate(QObject *parent):
|
||||
QAbstractItemDelegate(parent)
|
||||
{
|
||||
rowHeight = 40;
|
||||
}
|
||||
|
||||
MailListItemDelegate::~MailListItemDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MailListItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
QIcon ic = QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
|
||||
QString title = index.data(Qt::DisplayRole).toString();
|
||||
QString description = index.data(Qt::UserRole).toString();
|
||||
bool bolden_normal = index.data(Qt::UserRole + 2).toBool();
|
||||
|
||||
int imageSpace = 0;
|
||||
|
||||
if (detailedRendering)
|
||||
{
|
||||
imageSpace = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageSpace = 5;
|
||||
}
|
||||
|
||||
QRect r = option.rect;
|
||||
|
||||
QRect widget_rect = option.rect;
|
||||
/*
|
||||
QPen penText(currentThemePalette().text(), 1, Qt::SolidLine);
|
||||
QPen penItemSeparator(currentThemePalette().text(), 1, Qt::DotLine);
|
||||
|
||||
QFont fontHeadingNormal(currentFont(), 10, QFont::Normal);
|
||||
QFont fontDescriptionNormal(currentFont(), 9, QFont::Normal);
|
||||
QFont fontHeadingBold(currentFont(), 10, QFont::Bold);
|
||||
QFont fontDescriptionBold(currentFont(), 9, QFont::Bold);
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
{
|
||||
|
||||
painter->fillRect(widget_rect, currentThemePalette().highlight());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->fillRect(widget_rect, currentThemePalette().window());
|
||||
}
|
||||
|
||||
if (!ic.isNull())
|
||||
{
|
||||
if (detailedRendering)
|
||||
{
|
||||
QRect image_rect = option.rect.adjusted(5, 10, -10, -10);
|
||||
ic.paint(painter, image_rect, Qt::AlignVCenter | Qt::AlignLeft);
|
||||
|
||||
imageSpace = 55;
|
||||
}
|
||||
else
|
||||
{
|
||||
QRect image_rect = option.rect.adjusted(5, 5, -10, -5);
|
||||
ic.paint(painter, image_rect, Qt::AlignVCenter | Qt::AlignLeft);
|
||||
|
||||
imageSpace = 40;
|
||||
}
|
||||
}
|
||||
|
||||
if (bolden_normal && !(option.state & QStyle::State_Selected))
|
||||
{
|
||||
painter->setFont(fontHeadingNormal);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setFont(fontHeadingBold);
|
||||
}
|
||||
|
||||
if (detailedRendering)
|
||||
{
|
||||
r = option.rect.adjusted(imageSpace, 0, -10, -30);
|
||||
painter->setPen(penText);
|
||||
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom | Qt::AlignLeft, title, &r);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = option.rect.adjusted(imageSpace, 10, -10, -15);
|
||||
painter->setPen(penText);
|
||||
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter | Qt::AlignLeft, title, &r);
|
||||
}
|
||||
|
||||
r = option.rect.adjusted(imageSpace, 30, -10, 0);
|
||||
|
||||
if (bolden_normal && !(option.state & QStyle::State_Selected))
|
||||
{
|
||||
painter->setFont(fontDescriptionNormal);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setFont(fontDescriptionBold);
|
||||
}
|
||||
|
||||
if (detailedRendering)
|
||||
{
|
||||
painter->setPen(penText);
|
||||
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r);
|
||||
}
|
||||
|
||||
painter->setPen(penItemSeparator);
|
||||
painter->drawLine(widget_rect.left(), widget_rect.bottom(), widget_rect.left() + widget_rect.width(), widget_rect.bottom());
|
||||
*/
|
||||
}
|
||||
|
||||
QSize MailListItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
return QSize(200, rowHeight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MailList::MailList(QWidget *parent) :
|
||||
QTreeView(parent)
|
||||
{
|
||||
|
||||
QStringList headers;
|
||||
headers << tr("Title") << tr("Description") << tr("Cantidad") << tr("Cantidad total") << tr("Unidad") << tr("Precio Unitario")
|
||||
<< tr("Precio Total") << tr("Ganacia") << tr("Precio Total") << tr("Precio Total Venta");
|
||||
|
||||
//TreeModel *model = new TreeModel(headers, file.readAll());
|
||||
//setModel(model);
|
||||
|
||||
//connect(this, &QListWidget::itemClicked, this, &MailList::eventMailSelected);
|
||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this,
|
||||
//SLOT(handleSelectionChanged(QItemSelection))
|
||||
SLOT(eventMailSelected(QItemSelection))
|
||||
);
|
||||
}
|
||||
|
||||
MailList::~MailList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void MailList::Initialize(MailView* ptr)
|
||||
{
|
||||
mailViewPtr = ptr;
|
||||
}
|
||||
*/
|
||||
|
||||
void MailList::eventMailSelected(QItemSelection &selection)
|
||||
{
|
||||
// TODO: chequear esto:
|
||||
if(selection.indexes().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(selection.indexes().size() == 1)
|
||||
{
|
||||
QModelIndex index = selection.indexes().at(0);
|
||||
|
||||
//Person tp = index.data().value<Person>();
|
||||
//actualID = QString::number(tp.id());
|
||||
//ui->rightContent->setContactID(actualID);
|
||||
|
||||
//if(ui->rigthContent->currentIndex() != 1)
|
||||
// ui->rigthContent->setCurrentIndex(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ui->infoWidget->setType(axtMultiple);
|
||||
//ui->rigthContent->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
/*
|
||||
currentViewItem = selection;
|
||||
|
||||
QString currUID = currentViewItem->data(Qt::UserRole + 1).toString();
|
||||
|
||||
if (mailLookup.find(currUID) != mailLookup.end())
|
||||
{
|
||||
if (mailViewPtr != nullptr)
|
||||
{
|
||||
currentToken = mailLookup[currUID];
|
||||
emit MailSelected(currentToken);
|
||||
item->setData(Qt::UserRole + 2, QVariant(false));
|
||||
update();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void MailList::eventClearMailView()
|
||||
{
|
||||
//clear();
|
||||
mailLookup.clear();
|
||||
currentViewItem = nullptr;
|
||||
}
|
||||
|
||||
void MailList::eventMailListReceived(QVector<MailHeader>& mlist)
|
||||
{
|
||||
//clear();
|
||||
mailLookup.clear();
|
||||
currentViewItem = nullptr;
|
||||
|
||||
int count = mlist.size();
|
||||
|
||||
for (int index = 0; index < count; index++)
|
||||
{
|
||||
HeaderReceived(mlist[index]);
|
||||
}
|
||||
}
|
||||
|
||||
///TODO: que es esto??
|
||||
void MailList::HeaderReceived(MailHeader emlhdr)
|
||||
{
|
||||
QString temp_timestamp = emlhdr.GetTimeStamp();
|
||||
//QDateTime dateTime = QDateTime::fromString("ddd, dd MMM YYYY");
|
||||
|
||||
size_t tz_str_pos = -1;
|
||||
|
||||
tz_str_pos = temp_timestamp.indexOf('+');
|
||||
|
||||
if (tz_str_pos == -1)
|
||||
{
|
||||
tz_str_pos = temp_timestamp.indexOf('-');
|
||||
}
|
||||
|
||||
if (tz_str_pos != -1)
|
||||
{
|
||||
temp_timestamp = temp_timestamp.remove(tz_str_pos, temp_timestamp.length() - tz_str_pos);
|
||||
}
|
||||
|
||||
if (mailLookup.find(emlhdr.GetMessageId()) == mailLookup.end())
|
||||
{
|
||||
QString subject = emlhdr.GetSubject();
|
||||
if (subject.toLower().contains("utf-8"))
|
||||
{
|
||||
subject = emlhdr.GetSubject();
|
||||
}
|
||||
|
||||
QString description;
|
||||
description += emlhdr.GetFrom();
|
||||
description += ", ";
|
||||
description += temp_timestamp;
|
||||
|
||||
//QItemSelection* mailItem = new QItemSelection(this);
|
||||
//mailItem->setData(Qt::DisplayRole, QVariant(subject));
|
||||
//mailItem->setData(Qt::UserRole, QVariant(description));
|
||||
//mailItem->setData(Qt::UserRole + 1, QVariant(emlhdr.GetHeaderValue("UID")));
|
||||
|
||||
mailLookup[emlhdr.GetHeaderValue("UID")] = emlhdr;
|
||||
}
|
||||
}
|
||||
|
||||
void MailList::DeleteCurrent()
|
||||
{
|
||||
if (currentViewItem == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString currUID;// = currentViewItem->data(Qt::UserRole + 1).toString();
|
||||
|
||||
if (mailLookup.find(currUID) != mailLookup.end())
|
||||
{
|
||||
if (mailViewPtr != nullptr)
|
||||
{
|
||||
currentToken = mailLookup[currUID];
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (mailClientPtr->RemoveEmail(currentToken.GetHeaderValue("Account"), currentToken.GetHeaderValue("Directory"), currentToken.GetHeaderValue("UID"), currentToken.GetMessageId()))
|
||||
{
|
||||
removeItemWidget(currentViewItem);
|
||||
delete currentViewItem;
|
||||
currentViewItem = nullptr;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void MailList::FlagCurrent()
|
||||
{
|
||||
if (currentViewItem == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString currUID;// = currentViewItem->data(Qt::UserRole + 1).toString();
|
||||
|
||||
if (mailLookup.find(currUID) != mailLookup.end())
|
||||
{
|
||||
if (mailViewPtr != nullptr)
|
||||
{
|
||||
currentToken = mailLookup[currUID];
|
||||
}
|
||||
}
|
||||
|
||||
QString flag = "Flagged";
|
||||
|
||||
// if (mailClientPtr->FlagEmail(currentToken.GetHeaderValue("Account"), currentToken.GetHeaderValue("Directory"), currentToken.GetHeaderValue("UID"), flag))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MailList::MarkAsSeenCurrent()
|
||||
{
|
||||
if (currentViewItem == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString currUID;// = currentViewItem->data(Qt::UserRole + 1).toString();
|
||||
|
||||
if (mailLookup.find(currUID) != mailLookup.end())
|
||||
{
|
||||
if (mailViewPtr != nullptr)
|
||||
{
|
||||
currentToken = mailLookup[currUID];
|
||||
}
|
||||
}
|
||||
|
||||
// mailClientPtr->MarkEmailSeen(currentToken.GetHeaderValue("Account"), currentToken.GetHeaderValue("Directory"), currentToken.GetHeaderValue("UID"));
|
||||
}
|
||||
|
||||
void MailList::MoveToNext()
|
||||
{
|
||||
if (currentViewItem == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MailList::MoveToPrevious()
|
||||
{
|
||||
if (currentViewItem == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MailHeader MailList::GetCurrentToken()
|
||||
{
|
||||
return currentToken;
|
||||
}
|
||||
|
||||
void MailList::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
|
||||
qDebug() << width();
|
||||
|
||||
|
||||
if(width() > 400)
|
||||
{
|
||||
header()->show();
|
||||
QTreeView::resizeEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
header()->hide();
|
||||
QTreeView::resizeEvent(event);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef MAILLIST_H
|
||||
#define MAILLIST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "Mail.h"
|
||||
|
||||
|
||||
class MailListItemDelegate : public QAbstractItemDelegate
|
||||
{
|
||||
public:
|
||||
MailListItemDelegate(QObject *parent = Q_NULLPTR);
|
||||
virtual ~MailListItemDelegate();
|
||||
|
||||
void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
private:
|
||||
bool detailedRendering;
|
||||
int rowHeight;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class MailList : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MailList(QWidget *parent = Q_NULLPTR);
|
||||
~MailList();
|
||||
|
||||
//void Initialize(MailView* ptr);
|
||||
|
||||
void MoveToNext();
|
||||
void MoveToPrevious();
|
||||
|
||||
void DeleteCurrent();
|
||||
void FlagCurrent();
|
||||
void MarkAsSeenCurrent();
|
||||
|
||||
MailHeader GetCurrentToken();
|
||||
|
||||
signals:
|
||||
void MailSelected(MailHeader emlhdr);
|
||||
|
||||
public slots:
|
||||
void eventMailSelected(QItemSelection &selection);
|
||||
void eventMailListReceived(QVector<MailHeader>& mlist);
|
||||
void eventClearMailView();
|
||||
|
||||
private:
|
||||
void HeaderReceived(MailHeader emlhdr);
|
||||
|
||||
/*MailView*/QWidget* mailViewPtr;
|
||||
QItemSelection* currentViewItem;
|
||||
|
||||
MailHeader currentToken;
|
||||
QMap<QString, MailHeader> mailLookup;
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // MAILLIST_H
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "mlineeditbutton.h"
|
||||
#include "widgetcomboboxpopuptable.h"
|
||||
#include "mapplication.h"
|
||||
#include "mainwindow.h"
|
||||
#include "formproduct.h"
|
||||
#include "msqlquerymodel.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QtSql>
|
||||
|
||||
MLineEditButton::MLineEditButton(QWidget *parent) :
|
||||
QLineEdit(parent)
|
||||
{
|
||||
QAction *myAction = addAction(QIcon(":/resources/icons/down-arrow.svg"), QLineEdit::TrailingPosition);
|
||||
connect(myAction, &QAction::triggered, this, &MLineEditButton::onPopupShow);
|
||||
}
|
||||
|
||||
void MLineEditButton::onPopupShow()
|
||||
{
|
||||
auto *popup = new widgetComboboxPopupTable(this);
|
||||
popup->setModel(new MSqlQueryModel());
|
||||
|
||||
connect(popup->buttonNew, &QPushButton::released, this, &MLineEditButton::onPopupNewButton_release);
|
||||
connect(popup->buttonEdit, &QPushButton::released, this, &MLineEditButton::onPopupEditButton_release);
|
||||
connect(popup, &widgetComboboxPopupTable::onSelect, this, &MLineEditButton::getValuesFromPopup);
|
||||
|
||||
popup->setQueryEXEC("SELECT TYPE1, TYPE2, CODE, TITLE, UNIT_ID, PURCHASE_PRICE, SALE_PRICE FROM ELEMENT;");
|
||||
popup->tableView->setColumnWidth(0, 40);
|
||||
popup->tableView->setColumnWidth(1, 70);
|
||||
popup->tableView->setColumnWidth(2, 120);
|
||||
popup->tableView->setColumnWidth(3, 250);
|
||||
popup->tableView->setColumnWidth(4, 50);
|
||||
popup->tableView->setColumnWidth(5, 70);
|
||||
popup->tableView->setColumnWidth(6, 70);
|
||||
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(0, Qt::Horizontal, tr("Tipo"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(1, Qt::Horizontal, tr("Clase"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(2, Qt::Horizontal, tr("Código"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(3, Qt::Horizontal, tr("Resumen"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(4, Qt::Horizontal, tr("Coste"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(5, Qt::Horizontal, tr("Venta"));
|
||||
popup->tableView->horizontalHeader()->model()->setHeaderData(6, Qt::Horizontal, tr("Activo"));
|
||||
|
||||
|
||||
popup->move(mapToGlobal(rect().bottomLeft()).x(),
|
||||
mapToGlobal(rect().bottomLeft()).y());
|
||||
popup->show();
|
||||
}
|
||||
|
||||
void MLineEditButton::onPopupNewButton_release()
|
||||
{
|
||||
formProduct *form = dApp->mainWindow()->createFormProduct();
|
||||
form->show();
|
||||
}
|
||||
|
||||
void MLineEditButton::onPopupEditButton_release()
|
||||
{
|
||||
/*
|
||||
QModelIndex item = index;
|
||||
formProduct *form = dApp->mainWindow()->createFormProduct();
|
||||
|
||||
if (index.column() != 0)
|
||||
item = index.parent().child(index.row(), 0);
|
||||
form->openDocument(index.data().toString());
|
||||
form->show();
|
||||
*/
|
||||
}
|
||||
|
||||
void MLineEditButton::getValuesFromPopup(QStringList list)
|
||||
{
|
||||
setText(list[0]);
|
||||
|
||||
// TODO: si devuelve más de uno - ver como se hace
|
||||
/*
|
||||
for(auto item : list)
|
||||
{
|
||||
setText(item);
|
||||
qDebug() << item;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef MLINEEDITBUTTON_H
|
||||
#define MLINEEDITBUTTON_H
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
class MLineEditButton : public QLineEdit
|
||||
{
|
||||
public:
|
||||
explicit MLineEditButton(QWidget *parent = Q_NULLPTR);
|
||||
private slots:
|
||||
void onPopupShow();
|
||||
void onPopupNewButton_release();
|
||||
void onPopupEditButton_release();
|
||||
private:
|
||||
void getValuesFromPopup(QStringList list);
|
||||
};
|
||||
|
||||
#endif // MLINEEDITBUTTON_H
|
||||
@@ -0,0 +1,748 @@
|
||||
/*
|
||||
** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
|
||||
** Contact: http://www.hobrasoft.cz/
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file is under the terms of the GNU Lesser General Public License
|
||||
** version 2.1 as published by the Free Software Foundation and appearing
|
||||
** in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the
|
||||
** GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
*/
|
||||
|
||||
#include "mrichtextedit.h"
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QFontDatabase>
|
||||
#include <QInputDialog>
|
||||
#include <QColorDialog>
|
||||
#include <QTextList>
|
||||
#include <QtDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
#include <QSettings>
|
||||
#include <QBuffer>
|
||||
#include <QUrl>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QMenu>
|
||||
#include <QDialog>
|
||||
|
||||
#include "widgets/arrowrectangle.h"
|
||||
#include "widgets/colorpanel.h"
|
||||
#include "widgets/toolbutton.h"
|
||||
|
||||
#include <dinputdialog.h>
|
||||
|
||||
MRichTextEdit::MRichTextEdit(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
m_lastBlockList = 0;
|
||||
f_textedit->setTabStopWidth(40);
|
||||
|
||||
connect(f_textedit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
|
||||
this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat)));
|
||||
connect(f_textedit, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(slotCursorPositionChanged()));
|
||||
|
||||
fontChanged(f_textedit->font());
|
||||
bgColorChanged(f_textedit->textColor());
|
||||
|
||||
|
||||
/*
|
||||
m_fontsize_h1 = 18;
|
||||
m_fontsize_h2 = 16;
|
||||
m_fontsize_h3 = 14;
|
||||
m_fontsize_h4 = 12;
|
||||
*/
|
||||
// paragraph formatting
|
||||
/*
|
||||
m_paragraphItems << tr("Standard")
|
||||
<< tr("Heading 1")
|
||||
<< tr("Heading 2")
|
||||
<< tr("Heading 3")
|
||||
<< tr("Heading 4")
|
||||
<< tr("Monospace");
|
||||
f_paragraph->addItems(m_paragraphItems);
|
||||
|
||||
connect(f_paragraph, SIGNAL(activated(int)),
|
||||
this, SLOT(textStyle(int)));
|
||||
*/
|
||||
// undo & redo
|
||||
buttonUndo->setShortcut(QKeySequence::Undo);
|
||||
buttonRedo->setShortcut(QKeySequence::Redo);
|
||||
|
||||
connect(f_textedit->document(), SIGNAL(undoAvailable(bool)),
|
||||
buttonUndo, SLOT(setEnabled(bool)));
|
||||
connect(f_textedit->document(), SIGNAL(redoAvailable(bool)),
|
||||
buttonRedo, SLOT(setEnabled(bool)));
|
||||
|
||||
buttonUndo->setEnabled(f_textedit->document()->isUndoAvailable());
|
||||
buttonRedo->setEnabled(f_textedit->document()->isRedoAvailable());
|
||||
|
||||
connect(buttonUndo, SIGNAL(clicked()), f_textedit, SLOT(undo()));
|
||||
connect(buttonRedo, SIGNAL(clicked()), f_textedit, SLOT(redo()));
|
||||
|
||||
buttonUndo->hide();
|
||||
buttonRedo->hide();
|
||||
|
||||
// cut, copy & paste
|
||||
buttonCut->setShortcut(QKeySequence::Cut);
|
||||
buttonCopy->setShortcut(QKeySequence::Copy);
|
||||
buttonPaste->setShortcut(QKeySequence::Paste);
|
||||
|
||||
buttonCut->setEnabled(false);
|
||||
buttonCopy->setEnabled(false);
|
||||
|
||||
connect(buttonCut, SIGNAL(clicked()), f_textedit, SLOT(cut()));
|
||||
connect(buttonCopy, SIGNAL(clicked()), f_textedit, SLOT(copy()));
|
||||
connect(buttonPaste, SIGNAL(clicked()), f_textedit, SLOT(paste()));
|
||||
|
||||
connect(f_textedit, SIGNAL(copyAvailable(bool)), buttonCut, SLOT(setEnabled(bool)));
|
||||
connect(f_textedit, SIGNAL(copyAvailable(bool)), buttonCopy, SLOT(setEnabled(bool)));
|
||||
|
||||
buttonCut->hide();
|
||||
buttonCopy->hide();
|
||||
buttonPaste->hide();
|
||||
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged()));
|
||||
#endif
|
||||
|
||||
// link
|
||||
buttonLink->setShortcut(Qt::CTRL + Qt::Key_L);
|
||||
connect(buttonLink, SIGNAL(clicked(bool)), this, SLOT(textLink(bool)));
|
||||
|
||||
// bold, italic & underline
|
||||
buttonBold->setShortcut(Qt::CTRL + Qt::Key_B);
|
||||
buttonItalic->setShortcut(Qt::CTRL + Qt::Key_I);
|
||||
buttonUnderline->setShortcut(Qt::CTRL + Qt::Key_U);
|
||||
|
||||
connect(buttonBold, SIGNAL(clicked()), this, SLOT(textBold()));
|
||||
connect(buttonItalic, SIGNAL(clicked()), this, SLOT(textItalic()));
|
||||
connect(buttonUnderline, SIGNAL(clicked()), this, SLOT(textUnderline()));
|
||||
connect(buttonStrikeout, SIGNAL(clicked()), this, SLOT(textStrikeout()));
|
||||
|
||||
QAction* removeFormat = new QAction(tr("Remove character formatting"), this);
|
||||
removeFormat->setShortcut(QKeySequence("CTRL+M"));
|
||||
connect(removeFormat, SIGNAL(triggered()), this, SLOT(textRemoveFormat()));
|
||||
f_textedit->addAction(removeFormat);
|
||||
|
||||
QAction* removeAllFormat = new QAction(tr("Remove all formatting"), this);
|
||||
connect(removeAllFormat, SIGNAL(triggered()), this, SLOT(textRemoveAllFormat()));
|
||||
f_textedit->addAction(removeAllFormat);
|
||||
|
||||
QAction* textsource = new QAction(tr("Edit document source"), this);
|
||||
textsource->setShortcut(QKeySequence("CTRL+O"));
|
||||
connect(textsource, SIGNAL(triggered()), this, SLOT(textSource()));
|
||||
f_textedit->addAction(textsource);
|
||||
|
||||
QMenu* menu = new QMenu(this);
|
||||
menu->addAction(removeAllFormat);
|
||||
menu->addAction(removeFormat);
|
||||
menu->addAction(textsource);
|
||||
buttonMenu->setMenu(menu);
|
||||
buttonMenu->setPopupMode(QToolButton::InstantPopup);
|
||||
|
||||
// lists
|
||||
buttonListBullet->setShortcut(Qt::CTRL + Qt::Key_Minus);
|
||||
buttonListOrdered->setShortcut(Qt::CTRL + Qt::Key_Equal);
|
||||
|
||||
connect(buttonListBullet, SIGNAL(clicked(bool)), this, SLOT(listBullet(bool)));
|
||||
connect(buttonListOrdered, SIGNAL(clicked(bool)), this, SLOT(listOrdered(bool)));
|
||||
|
||||
// indentation
|
||||
buttonIndentDec->setShortcut(Qt::CTRL + Qt::Key_Comma);
|
||||
buttonIndentInc->setShortcut(Qt::CTRL + Qt::Key_Period);
|
||||
|
||||
connect(buttonIndentInc, SIGNAL(clicked()), this, SLOT(increaseIndentation()));
|
||||
connect(buttonIndentDec, SIGNAL(clicked()), this, SLOT(decreaseIndentation()));
|
||||
|
||||
// font family
|
||||
QFont font;
|
||||
font.setPointSize(8);
|
||||
fontComboBox->setFont(font);
|
||||
connect(fontComboBox, SIGNAL(activated(QString)), this, SLOT(textFontFamily(QString)));
|
||||
fontComboBox->setCurrentFont(QApplication::font().family());// >setCurrentIndex(fontComboBox->findText(QString::number(QApplication::font().pointSize()))); //<- cambiar
|
||||
|
||||
// font size
|
||||
QFontDatabase db;
|
||||
foreach (int size, db.standardSizes())
|
||||
comboFontSize->addItem(QString::number(size));
|
||||
|
||||
connect(comboFontSize, SIGNAL(activated(QString)), this, SLOT(textSize(QString)));
|
||||
comboFontSize->setCurrentIndex(comboFontSize->findText(QString::number(QApplication::font().pointSize())));
|
||||
|
||||
// text foreground color
|
||||
QPixmap pix(16, 16);
|
||||
pix.fill(QApplication::palette().foreground().color());
|
||||
buttonFGColor->setIcon(pix);
|
||||
|
||||
connect(buttonFGColor, SIGNAL(clicked()), this, SLOT(textFgColor()));
|
||||
|
||||
// text background color
|
||||
pix.fill(QApplication::palette().background().color());
|
||||
buttonBGColor->setIcon(pix);
|
||||
|
||||
connect(buttonBGColor, SIGNAL(clicked()), this, SLOT(textBgColor()));
|
||||
|
||||
// images
|
||||
connect(buttonImage, SIGNAL(clicked()), this, SLOT(insertImage()));
|
||||
}
|
||||
|
||||
void MRichTextEdit::textSource()
|
||||
{
|
||||
QDialog* dialog = new QDialog(this);
|
||||
QPlainTextEdit* pte = new QPlainTextEdit(dialog);
|
||||
pte->setPlainText(f_textedit->toHtml());
|
||||
QGridLayout* gl = new QGridLayout(dialog);
|
||||
gl->addWidget(pte, 0, 0, 1, 1);
|
||||
dialog->setWindowTitle(tr("Document source"));
|
||||
dialog->setMinimumWidth(400);
|
||||
dialog->setMinimumHeight(600);
|
||||
dialog->exec();
|
||||
|
||||
f_textedit->setHtml(pte->toPlainText());
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void MRichTextEdit::textRemoveFormat()
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontWeight(QFont::Normal);
|
||||
fmt.setFontUnderline(false);
|
||||
fmt.setFontStrikeOut(false);
|
||||
fmt.setFontItalic(false);
|
||||
fmt.setFontPointSize(9);
|
||||
// fmt.setFontFamily ("Helvetica");
|
||||
// fmt.setFontStyleHint (QFont::SansSerif);
|
||||
// fmt.setFontFixedPitch (true);
|
||||
|
||||
buttonBold->setChecked(false);
|
||||
buttonUnderline->setChecked(false);
|
||||
buttonItalic->setChecked(false);
|
||||
buttonStrikeout->setChecked(false);
|
||||
comboFontSize->setCurrentIndex(comboFontSize->findText("9"));
|
||||
|
||||
// QTextBlockFormat bfmt = cursor.blockFormat();
|
||||
// bfmt->setIndent(0);
|
||||
|
||||
fmt.clearBackground();
|
||||
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textRemoveAllFormat()
|
||||
{
|
||||
buttonBold->setChecked(false);
|
||||
buttonUnderline->setChecked(false);
|
||||
buttonItalic->setChecked(false);
|
||||
buttonStrikeout->setChecked(false);
|
||||
comboFontSize->setCurrentIndex(comboFontSize->findText("9"));
|
||||
QString text = f_textedit->toPlainText();
|
||||
f_textedit->setPlainText(text);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textBold()
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontWeight(buttonBold->isChecked() ? QFont::Bold : QFont::Normal);
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::focusInEvent(QFocusEvent*)
|
||||
{
|
||||
f_textedit->setFocus(Qt::TabFocusReason);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textUnderline()
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontUnderline(buttonUnderline->isChecked());
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textItalic()
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontItalic(buttonItalic->isChecked());
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textStrikeout()
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontStrikeOut(buttonStrikeout->isChecked());
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textFontFamily(const QString& p)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontFamily(this->fontComboBox->currentFont().family());
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
void MRichTextEdit::textSize(const QString& p)
|
||||
{
|
||||
qreal pointSize = p.toFloat();
|
||||
if (p.toFloat() > 0) {
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontPointSize(pointSize);
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
}
|
||||
|
||||
void MRichTextEdit::textLink(bool checked)
|
||||
{
|
||||
bool unlink = false;
|
||||
QTextCharFormat fmt;
|
||||
if (checked)
|
||||
{
|
||||
QString url = f_textedit->currentCharFormat().anchorHref();
|
||||
bool ok;
|
||||
QString newUrl = DInputDialog::getText(NULL, tr("Create a link"),
|
||||
tr("Link URL:"), QLineEdit::Normal,
|
||||
url,
|
||||
&ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
fmt.setAnchor(true);
|
||||
fmt.setAnchorHref(newUrl);
|
||||
fmt.setForeground(QApplication::palette().color(QPalette::Link));
|
||||
fmt.setFontUnderline(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink = true;
|
||||
}
|
||||
if (unlink)
|
||||
{
|
||||
fmt.setAnchor(false);
|
||||
fmt.setForeground(QApplication::palette().color(QPalette::Text));
|
||||
fmt.setFontUnderline(false);
|
||||
}
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
}
|
||||
|
||||
/*
|
||||
void MRichTextEdit::textStyle(int index)
|
||||
{
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
cursor.beginEditBlock();
|
||||
|
||||
// standard
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::BlockUnderCursor);
|
||||
}
|
||||
QTextCharFormat fmt;
|
||||
cursor.setCharFormat(fmt);
|
||||
f_textedit->setCurrentCharFormat(fmt);
|
||||
|
||||
if (index == ParagraphHeading1
|
||||
|| index == ParagraphHeading2
|
||||
|| index == ParagraphHeading3
|
||||
|| index == ParagraphHeading4) {
|
||||
if (index == ParagraphHeading1) {
|
||||
fmt.setFontPointSize(m_fontsize_h1);
|
||||
}
|
||||
if (index == ParagraphHeading2) {
|
||||
fmt.setFontPointSize(m_fontsize_h2);
|
||||
}
|
||||
if (index == ParagraphHeading3) {
|
||||
fmt.setFontPointSize(m_fontsize_h3);
|
||||
}
|
||||
if (index == ParagraphHeading4) {
|
||||
fmt.setFontPointSize(m_fontsize_h4);
|
||||
}
|
||||
if (index == ParagraphHeading2 || index == ParagraphHeading4) {
|
||||
fmt.setFontItalic(true);
|
||||
}
|
||||
|
||||
fmt.setFontWeight(QFont::Bold);
|
||||
}
|
||||
if (index == ParagraphMonospace) {
|
||||
fmt = cursor.charFormat();
|
||||
fmt.setFontFamily("Monospace");
|
||||
fmt.setFontStyleHint(QFont::Monospace);
|
||||
fmt.setFontFixedPitch(true);
|
||||
}
|
||||
cursor.setCharFormat(fmt);
|
||||
f_textedit->setCurrentCharFormat(fmt);
|
||||
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
*/
|
||||
|
||||
void MRichTextEdit::textFgColor()
|
||||
{
|
||||
auto* m_colorPanel = new ColorPanel(this);
|
||||
qApp->setProperty("_d_isDxcb", false);
|
||||
auto* m_colorARect = new ArrowRectangle(DArrowRectangle::ArrowTop);
|
||||
qApp->setProperty("_d_isDxcb", true);
|
||||
m_colorARect->setWindowFlags(Qt::Widget);
|
||||
//m_colorARect->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
m_colorARect->setArrowWidth(18);
|
||||
m_colorARect->setArrowHeight(10);
|
||||
m_colorARect->setContent(m_colorPanel);
|
||||
m_colorARect->setBackgroundColor(QColor(255, 255, 255, 255));
|
||||
|
||||
connect(m_colorPanel, &ColorPanel::updateHeight, this, [=] {
|
||||
m_colorARect->setContent(m_colorPanel);
|
||||
});
|
||||
|
||||
m_colorARect->raise();
|
||||
m_colorARect->show(buttonFGColor->mapToGlobal(buttonFGColor->rect().bottomLeft()).x() + buttonFGColor->width() / 2,
|
||||
buttonFGColor->mapToGlobal(buttonFGColor->rect().bottomLeft()).y() + 2);
|
||||
|
||||
connect(m_colorARect, &ArrowRectangle::hideWindow, this, [=] {
|
||||
QColor col = m_colorPanel->getColor();
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
}
|
||||
QTextCharFormat fmt = cursor.charFormat();
|
||||
if (col.isValid()) {
|
||||
fmt.setForeground(col);
|
||||
}
|
||||
else {
|
||||
fmt.clearForeground();
|
||||
}
|
||||
cursor.setCharFormat(fmt);
|
||||
f_textedit->setCurrentCharFormat(fmt);
|
||||
fgColorChanged(col);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void MRichTextEdit::textBgColor()
|
||||
{
|
||||
auto* m_colorPanel = new ColorPanel(this);
|
||||
qApp->setProperty("_d_isDxcb", false);
|
||||
auto* m_colorARect = new ArrowRectangle(DArrowRectangle::ArrowTop);
|
||||
qApp->setProperty("_d_isDxcb", true);
|
||||
m_colorARect->setWindowFlags(Qt::Widget);
|
||||
m_colorARect->setArrowWidth(18);
|
||||
m_colorARect->setArrowHeight(10);
|
||||
m_colorARect->setContent(m_colorPanel);
|
||||
m_colorARect->setBackgroundColor(QColor(255, 255, 255, 255));
|
||||
|
||||
connect(m_colorPanel, &ColorPanel::updateHeight, this, [=]
|
||||
{
|
||||
m_colorARect->setContent(m_colorPanel);
|
||||
});
|
||||
|
||||
m_colorARect->raise();
|
||||
m_colorARect->show(buttonBGColor->mapToGlobal(buttonBGColor->rect().bottomLeft()).x() + buttonBGColor->width() / 2,
|
||||
buttonBGColor->mapToGlobal(buttonBGColor->rect().bottomLeft()).y() + 2);
|
||||
|
||||
connect(m_colorARect, &ArrowRectangle::hideWindow, this, [=]
|
||||
{
|
||||
QColor col = m_colorPanel->getColor();
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
}
|
||||
QTextCharFormat fmt = cursor.charFormat();
|
||||
if (col.isValid()) {
|
||||
fmt.setBackground(col);
|
||||
}
|
||||
else {
|
||||
fmt.clearBackground();
|
||||
}
|
||||
cursor.setCharFormat(fmt);
|
||||
f_textedit->setCurrentCharFormat(fmt);
|
||||
bgColorChanged(col);
|
||||
});
|
||||
|
||||
/*QColor col = QColorDialog::getColor(f_textedit->textBackgroundColor(), this);
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
}
|
||||
QTextCharFormat fmt = cursor.charFormat();
|
||||
if (col.isValid()) {
|
||||
fmt.setBackground(col);
|
||||
} else {
|
||||
fmt.clearBackground();
|
||||
}
|
||||
cursor.setCharFormat(fmt);
|
||||
f_textedit->setCurrentCharFormat(fmt);
|
||||
bgColorChanged(col);*/
|
||||
}
|
||||
|
||||
void MRichTextEdit::listBullet(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
list(checked, QTextListFormat::ListDisc);
|
||||
}
|
||||
|
||||
void MRichTextEdit::listOrdered(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
buttonListBullet->setChecked(false);
|
||||
}
|
||||
list(checked, QTextListFormat::ListDecimal);
|
||||
}
|
||||
|
||||
void MRichTextEdit::list(bool checked, QTextListFormat::Style style)
|
||||
{
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
cursor.beginEditBlock();
|
||||
if (!checked) {
|
||||
QTextBlockFormat obfmt = cursor.blockFormat();
|
||||
QTextBlockFormat bfmt;
|
||||
bfmt.setIndent(obfmt.indent());
|
||||
cursor.setBlockFormat(bfmt);
|
||||
}
|
||||
else {
|
||||
QTextListFormat listFmt;
|
||||
if (cursor.currentList()) {
|
||||
listFmt = cursor.currentList()->format();
|
||||
}
|
||||
listFmt.setStyle(style);
|
||||
cursor.createList(listFmt);
|
||||
}
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
void MRichTextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat& format)
|
||||
{
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
}
|
||||
cursor.mergeCharFormat(format);
|
||||
f_textedit->mergeCurrentCharFormat(format);
|
||||
f_textedit->setFocus(Qt::TabFocusReason);
|
||||
}
|
||||
|
||||
void MRichTextEdit::slotCursorPositionChanged()
|
||||
{
|
||||
QTextList* l = f_textedit->textCursor().currentList();
|
||||
if (m_lastBlockList && (l == m_lastBlockList || (l != 0 && m_lastBlockList != 0
|
||||
&& l->format().style() == m_lastBlockList->format().style()))) {
|
||||
return;
|
||||
}
|
||||
m_lastBlockList = l;
|
||||
if (l) {
|
||||
QTextListFormat lfmt = l->format();
|
||||
if (lfmt.style() == QTextListFormat::ListDisc) {
|
||||
buttonListBullet->setChecked(true);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
else if (lfmt.style() == QTextListFormat::ListDecimal) {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(true);
|
||||
}
|
||||
else {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MRichTextEdit::fontChanged(const QFont& f)
|
||||
{
|
||||
|
||||
fontComboBox->setCurrentFont(QFont(f.family()) );
|
||||
comboFontSize->setCurrentIndex(comboFontSize->findText(QString::number(f.pointSize())));
|
||||
buttonBold->setChecked(f.bold());
|
||||
buttonItalic->setChecked(f.italic());
|
||||
buttonUnderline->setChecked(f.underline());
|
||||
buttonStrikeout->setChecked(f.strikeOut());
|
||||
|
||||
/*
|
||||
if (f.pointSize() == m_fontsize_h1) {
|
||||
f_paragraph->setCurrentIndex(ParagraphHeading1);
|
||||
}
|
||||
else if (f.pointSize() == m_fontsize_h2) {
|
||||
f_paragraph->setCurrentIndex(ParagraphHeading2);
|
||||
}
|
||||
else if (f.pointSize() == m_fontsize_h3) {
|
||||
f_paragraph->setCurrentIndex(ParagraphHeading3);
|
||||
}
|
||||
else if (f.pointSize() == m_fontsize_h4) {
|
||||
f_paragraph->setCurrentIndex(ParagraphHeading4);
|
||||
}
|
||||
else {
|
||||
if (f.fixedPitch() && f.family() == "Monospace") {
|
||||
f_paragraph->setCurrentIndex(ParagraphMonospace);
|
||||
}
|
||||
else {
|
||||
f_paragraph->setCurrentIndex(ParagraphStandard);
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (f_textedit->textCursor().currentList()) {
|
||||
QTextListFormat lfmt = f_textedit->textCursor().currentList()->format();
|
||||
if (lfmt.style() == QTextListFormat::ListDisc) {
|
||||
buttonListBullet->setChecked(true);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
else if (lfmt.style() == QTextListFormat::ListDecimal) {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(true);
|
||||
}
|
||||
else {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
buttonListBullet->setChecked(false);
|
||||
buttonListOrdered->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MRichTextEdit::fgColorChanged(const QColor& c)
|
||||
{
|
||||
QPixmap pix(16, 16);
|
||||
if (c.isValid()) {
|
||||
pix.fill(c);
|
||||
}
|
||||
else {
|
||||
pix.fill(QApplication::palette().foreground().color());
|
||||
}
|
||||
buttonFGColor->setIcon(pix);
|
||||
}
|
||||
|
||||
void MRichTextEdit::bgColorChanged(const QColor& c)
|
||||
{
|
||||
QPixmap pix(16, 16);
|
||||
if (c.isValid()) {
|
||||
pix.fill(c);
|
||||
}
|
||||
else {
|
||||
pix.fill(QApplication::palette().background().color());
|
||||
}
|
||||
buttonBGColor->setIcon(pix);
|
||||
}
|
||||
|
||||
void MRichTextEdit::slotCurrentCharFormatChanged(const QTextCharFormat& format)
|
||||
{
|
||||
fontChanged(format.font());
|
||||
bgColorChanged((format.background().isOpaque()) ? format.background().color() : QColor());
|
||||
fgColorChanged((format.foreground().isOpaque()) ? format.foreground().color() : QColor());
|
||||
buttonLink->setChecked(format.isAnchor());
|
||||
}
|
||||
|
||||
void MRichTextEdit::slotClipboardDataChanged()
|
||||
{
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
if (const QMimeData* md = QApplication::clipboard()->mimeData())
|
||||
buttonPaste->setEnabled(md->hasText());
|
||||
#endif
|
||||
}
|
||||
|
||||
QString MRichTextEdit::toHtml() const
|
||||
{
|
||||
QString s = f_textedit->toHtml();
|
||||
// convert emails to links
|
||||
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1<a href=\"mailto:\\2\">\\2</a>");
|
||||
// convert links
|
||||
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1<a href=\"\\2\">\\2</a>");
|
||||
// see also: Utils::linkify()
|
||||
return s;
|
||||
}
|
||||
|
||||
void MRichTextEdit::increaseIndentation()
|
||||
{
|
||||
indent(+1);
|
||||
}
|
||||
|
||||
void MRichTextEdit::decreaseIndentation()
|
||||
{
|
||||
indent(-1);
|
||||
}
|
||||
|
||||
void MRichTextEdit::indent(int delta)
|
||||
{
|
||||
QTextCursor cursor = f_textedit->textCursor();
|
||||
cursor.beginEditBlock();
|
||||
QTextBlockFormat bfmt = cursor.blockFormat();
|
||||
int ind = bfmt.indent();
|
||||
if (ind + delta >= 0) {
|
||||
bfmt.setIndent(ind + delta);
|
||||
}
|
||||
cursor.setBlockFormat(bfmt);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
void MRichTextEdit::setText(const QString& text)
|
||||
{
|
||||
if (text.isEmpty())
|
||||
{
|
||||
setPlainText(text);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
if (text[0] == '<')
|
||||
{
|
||||
setHtml(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPlainText(text);
|
||||
}*/
|
||||
|
||||
|
||||
setHtml(text);
|
||||
f_textedit->moveCursor(QTextCursor::End);
|
||||
}
|
||||
|
||||
void MRichTextEdit::insertHtml(const QString &text)
|
||||
{
|
||||
f_textedit->insertHtml(text);
|
||||
}
|
||||
|
||||
void MRichTextEdit::insertImage()
|
||||
{
|
||||
QSettings s;
|
||||
QString attdir = s.value("general/filedialog-path").toString();
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
tr("Select an image"),
|
||||
attdir,
|
||||
tr("JPEG (*.jpg);; GIF (*.gif);; PNG (*.png);; BMP (*.bmp);; All (*)"));
|
||||
QImage image = QImageReader(file).read();
|
||||
|
||||
f_textedit->dropImage(image, QFileInfo(file).suffix().toUpper().toLocal8Bit().data());
|
||||
}
|
||||
|
||||
void MRichTextEdit::setDefaultFont(QFont fontFamily)
|
||||
{
|
||||
fontComboBox->setCurrentFont(fontFamily.family());
|
||||
textFontFamily(fontFamily.family());
|
||||
}
|
||||
|
||||
void MRichTextEdit::setDefaultFontSize(int size)
|
||||
{
|
||||
QString sSize = QString("%i").arg(size);
|
||||
comboFontSize->setCurrentText(sSize);
|
||||
textSize(sSize);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
|
||||
** Contact: http://www.hobrasoft.cz/
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file is under the terms of the GNU Lesser General Public License
|
||||
** version 2.1 as published by the Free Software Foundation and appearing
|
||||
** in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the
|
||||
** GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
*/
|
||||
|
||||
#ifndef _MRICHTEXTEDIT_H_
|
||||
#define _MRICHTEXTEDIT_H_
|
||||
|
||||
#include <QPointer>
|
||||
#include "ui_mrichtextedit.h"
|
||||
|
||||
#include <DtkWidgets>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
/**
|
||||
* @Brief A simple rich-text editor
|
||||
*/
|
||||
class MRichTextEdit : public QWidget, protected Ui::MRichTextEdit
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MRichTextEdit(QWidget *parent = 0);
|
||||
|
||||
QString toPlainText() const { return f_textedit->toPlainText(); }
|
||||
QString toHtml() const;
|
||||
QTextDocument *document() { return f_textedit->document(); }
|
||||
QTextCursor textCursor() const { return f_textedit->textCursor(); }
|
||||
void setTextCursor(const QTextCursor& cursor) { f_textedit->setTextCursor(cursor); }
|
||||
|
||||
void setDefaultFont(QFont fontFamily);
|
||||
void setDefaultFontSize(int size);
|
||||
|
||||
public slots:
|
||||
void setText(const QString &text);
|
||||
void insertHtml(const QString &text);
|
||||
|
||||
protected slots:
|
||||
void setPlainText(const QString &text) { f_textedit->setPlainText(text); }
|
||||
void setHtml(const QString &text) { f_textedit->setHtml(text); }
|
||||
void textRemoveFormat();
|
||||
void textRemoveAllFormat();
|
||||
void textBold();
|
||||
void textUnderline();
|
||||
void textStrikeout();
|
||||
void textItalic();
|
||||
void textSize(const QString &p);
|
||||
void textLink(bool checked);
|
||||
//void textStyle(int index);
|
||||
void textFgColor();
|
||||
void textBgColor();
|
||||
void listBullet(bool checked);
|
||||
void listOrdered(bool checked);
|
||||
void slotCurrentCharFormatChanged(const QTextCharFormat &format);
|
||||
void slotCursorPositionChanged();
|
||||
void slotClipboardDataChanged();
|
||||
void increaseIndentation();
|
||||
void decreaseIndentation();
|
||||
void insertImage();
|
||||
void textSource();
|
||||
void textFontFamily(const QString &p);
|
||||
|
||||
protected:
|
||||
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
|
||||
void fontChanged(const QFont &f);
|
||||
void fgColorChanged(const QColor &c);
|
||||
void bgColorChanged(const QColor &c);
|
||||
void list(bool checked, QTextListFormat::Style style);
|
||||
void indent(int delta);
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
|
||||
QStringList m_paragraphItems;
|
||||
int m_fontsize_h1;
|
||||
int m_fontsize_h2;
|
||||
int m_fontsize_h3;
|
||||
int m_fontsize_h4;
|
||||
|
||||
enum ParagraphItems { ParagraphStandard = 0,
|
||||
ParagraphHeading1,
|
||||
ParagraphHeading2,
|
||||
ParagraphHeading3,
|
||||
ParagraphHeading4,
|
||||
ParagraphMonospace };
|
||||
|
||||
QPointer<QTextList> m_lastBlockList;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,792 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MRichTextEdit</class>
|
||||
<widget class="QWidget" name="MRichTextEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>799</width>
|
||||
<height>345</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="separatorLine">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border: 1px solid rgba(0, 0, 0, 0.05);
|
||||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="f_toolbar" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonBold">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string notr="true">Bold (CTRL+B)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bold</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/bold-text.svg</normaloff>:/images/resources/icons/bold-text.svg</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonItalic">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Italic (CTRL+I)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Italic</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/italic-text.svg</normaloff>:/images/resources/icons/italic-text.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonUnderline">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Underline (CTRL+U)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Underline</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/underline-text.svg</normaloff>:/images/resources/icons/underline-text.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonStrikeout">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Strike Out</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/strikethrough.svg</normaloff>:/images/resources/icons/strikethrough.svg</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_7">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFontComboBox" name="fontComboBox">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboFontSize">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Font size</string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonFGColor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Text foreground color</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/font color.svg</normaloff>:/images/resources/icons/font color.svg</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonBGColor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Text background color</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/highlight color.svg</normaloff>:/images/resources/icons/highlight color.svg</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_8">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonListOrdered">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ordered list (CTRL+=)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ordered list</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/number.svg</normaloff>:/images/resources/icons/number.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonListBullet">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Bullet list (CTRL+-)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bullet list</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/bullets.svg</normaloff>:/images/resources/icons/bullets.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonIndentInc">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Increase indentation (CTRL+.)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Increase indentation</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/indent_increase.svg</normaloff>:/images/resources/icons/indent_increase.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonIndentDec">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Decrease indentation (CTRL+,)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Decrease indentation</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/indent_decrease.svg</normaloff>:/images/resources/icons/indent_decrease.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonLink">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Link (CTRL+L)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Link</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/link.svg</normaloff>:/images/resources/icons/link.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonImage">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/resources/icons/image.svg</normaloff>:/images/resources/icons/image.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonCopy">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Copy (CTRL+C)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-copy">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonCut">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Cut (CTRL+X)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-cut">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonPaste">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Paste (CTRL+V)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-paste">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonUndo">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Undo (CTRL+Z)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Undo</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-undo">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonRedo">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-redo">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonMenu">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>line_4</zorder>
|
||||
<zorder>line</zorder>
|
||||
<zorder>line_3</zorder>
|
||||
<zorder>buttonMenu</zorder>
|
||||
<zorder>buttonBold</zorder>
|
||||
<zorder>buttonItalic</zorder>
|
||||
<zorder>buttonStrikeout</zorder>
|
||||
<zorder>fontComboBox</zorder>
|
||||
<zorder>comboFontSize</zorder>
|
||||
<zorder>buttonUnderline</zorder>
|
||||
<zorder>line_7</zorder>
|
||||
<zorder>line_8</zorder>
|
||||
<zorder>buttonFGColor</zorder>
|
||||
<zorder>buttonBGColor</zorder>
|
||||
<zorder>buttonUndo</zorder>
|
||||
<zorder>buttonRedo</zorder>
|
||||
<zorder>buttonListBullet</zorder>
|
||||
<zorder>buttonListOrdered</zorder>
|
||||
<zorder>buttonIndentDec</zorder>
|
||||
<zorder>buttonIndentInc</zorder>
|
||||
<zorder>buttonPaste</zorder>
|
||||
<zorder>buttonCut</zorder>
|
||||
<zorder>buttonLink</zorder>
|
||||
<zorder>buttonCopy</zorder>
|
||||
<zorder>buttonImage</zorder>
|
||||
<zorder>horizontalSpacer_2</zorder>
|
||||
<zorder>horizontalSpacer_3</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="separatorLine_2">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border: 1px solid rgba(0, 0, 0, 0.05);
|
||||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MTextEdit" name="f_textedit">
|
||||
<property name="autoFormatting">
|
||||
<set>QTextEdit::AutoNone</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>mtextedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>f_textedit</tabstop>
|
||||
<tabstop>buttonMenu</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,146 @@
|
||||
#include "msqlquerymodel.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
|
||||
MSqlQueryModel::MSqlQueryModel(QObject *parent) :
|
||||
QSqlQueryModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QVariant MSqlQueryModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
return false;
|
||||
|
||||
QVariant value = QSqlQueryModel::data(index,role);
|
||||
//if(role==Qt::TextColorRole && index.column()==0)
|
||||
// return qVariantFromValue(QColor(Qt::red));
|
||||
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
//case Qt::EditRole:
|
||||
{
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
switch (QSqlQueryModel::data(index, Qt::DisplayRole).toInt())//(data(index).toInt())
|
||||
{
|
||||
case 0:
|
||||
return tr("Elemento Compuesto");
|
||||
|
||||
case 1:
|
||||
return tr("Material");
|
||||
|
||||
case 2:
|
||||
return tr("Mano de Obra");
|
||||
|
||||
case 3:
|
||||
return tr("Maquinaria");
|
||||
|
||||
case 4:
|
||||
return tr("Porcentajes");
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
switch (QSqlQueryModel::data(index, Qt::DisplayRole).toInt())//(data(index).toInt())
|
||||
{
|
||||
case 0:
|
||||
return tr("Servicio");
|
||||
|
||||
case 1:
|
||||
return tr("Producto");
|
||||
}
|
||||
}
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
{
|
||||
QLocale locale = QLocale("es_ES");
|
||||
QString s = locale.toString(value.toDouble(), 'f', 2) + " €";
|
||||
return s;
|
||||
}
|
||||
|
||||
case 6:
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
if(index.column() == 0)
|
||||
{
|
||||
switch (QSqlQueryModel::data(index, Qt::DisplayRole).toInt())//(data(index).toInt())
|
||||
{
|
||||
case 0:
|
||||
return QIcon(":/resources/icons/box.svg");
|
||||
|
||||
case 1:
|
||||
return QIcon(":/resources/icons/blocks.svg");
|
||||
|
||||
case 2:
|
||||
return QIcon(":/resources/icons/helmet.svg");
|
||||
|
||||
case 3:
|
||||
return QIcon(":/resources/icons/gear.svg");
|
||||
|
||||
case 4:
|
||||
return QIcon(":/resources/icons/percentage.svg");
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
switch (index.column())
|
||||
{
|
||||
case 4:
|
||||
case 5:
|
||||
{
|
||||
return int(Qt::AlignRight | Qt::AlignTop);
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
return int(Qt::AlignCenter | Qt::AlignTop);
|
||||
}
|
||||
default:
|
||||
return int(Qt::AlignLeft | Qt::AlignTop);
|
||||
}
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
|
||||
if (index.column() == 6)
|
||||
return (QSqlQueryModel::data(index).toBool() == true) ? Qt::Checked : Qt::Unchecked;
|
||||
else
|
||||
return QVariant();
|
||||
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef MSQLQUERYMODEL_H
|
||||
#define MSQLQUERYMODEL_H
|
||||
|
||||
#include <QSqlQueryModel>
|
||||
|
||||
class MSqlQueryModel : public QSqlQueryModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MSqlQueryModel(QObject *parent = Q_NULLPTR);
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // MSQLQUERYMODEL_H
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "mtextedit.h"
|
||||
#include <QTextDocument>
|
||||
#include <QTextCursor>
|
||||
#include <QImage>
|
||||
#include <QByteArray>
|
||||
#include <QBuffer>
|
||||
#include <stdlib.h>
|
||||
|
||||
MTextEdit::MTextEdit(QWidget* parent)
|
||||
: QTextEdit(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool MTextEdit::canInsertFromMimeData(const QMimeData* source) const
|
||||
{
|
||||
return source->hasImage() || QTextEdit::canInsertFromMimeData(source);
|
||||
}
|
||||
|
||||
void MTextEdit::insertFromMimeData(const QMimeData* source)
|
||||
{
|
||||
if (source->hasImage())
|
||||
{
|
||||
QStringList formats = source->formats();
|
||||
QString format;
|
||||
for (int i = 0; i < formats.size(); i++)
|
||||
{
|
||||
if (formats[i] == "image/bmp")
|
||||
{
|
||||
format = "BMP";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/jpeg")
|
||||
{
|
||||
format = "JPG";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/jpg") {
|
||||
format = "JPG";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/gif") {
|
||||
format = "GIF";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/png") {
|
||||
format = "PNG";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/pbm") {
|
||||
format = "PBM";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/pgm") {
|
||||
format = "PGM";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/ppm") {
|
||||
format = "PPM";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/tiff") {
|
||||
format = "TIFF";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/xbm") {
|
||||
format = "XBM";
|
||||
break;
|
||||
}
|
||||
if (formats[i] == "image/xpm") {
|
||||
format = "XPM";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!format.isEmpty())
|
||||
{
|
||||
// dropImage(qvariant_cast<QImage>(source->imageData()), format);
|
||||
dropImage(qvariant_cast<QImage>(source->imageData()), "JPG"); // Sorry, ale cokoli jiného dlouho trvá
|
||||
return;
|
||||
}
|
||||
}
|
||||
QTextEdit::insertFromMimeData(source);
|
||||
}
|
||||
|
||||
QMimeData* MTextEdit::createMimeDataFromSelection() const
|
||||
{
|
||||
return QTextEdit::createMimeDataFromSelection();
|
||||
}
|
||||
|
||||
void MTextEdit::dropImage(const QImage& image, const QString& format)
|
||||
{
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
image.save(&buffer, format.toLocal8Bit().data());
|
||||
buffer.close();
|
||||
QByteArray base64 = bytes.toBase64();
|
||||
QByteArray base64l;
|
||||
for (int i = 0; i < base64.size(); i++)
|
||||
{
|
||||
base64l.append(base64[i]);
|
||||
if (i % 80 == 0)
|
||||
{
|
||||
base64l.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
QTextCursor cursor = textCursor();
|
||||
QTextImageFormat imageFormat;
|
||||
imageFormat.setWidth(image.width());
|
||||
imageFormat.setHeight(image.height());
|
||||
imageFormat.setName(QString("data:image/%1;base64,%2")
|
||||
.arg(QString("%1.%2").arg(rand()).arg(format))
|
||||
.arg(base64l.data()));
|
||||
cursor.insertImage(imageFormat);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef _MTEXTEDIT_H_
|
||||
#define _MTEXTEDIT_H_
|
||||
|
||||
#include <QTextEdit>
|
||||
#include <QMimeData>
|
||||
#include <QImage>
|
||||
|
||||
class MTextEdit : public QTextEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MTextEdit(QWidget *parent);
|
||||
|
||||
void dropImage(const QImage& image, const QString& format);
|
||||
|
||||
protected:
|
||||
bool canInsertFromMimeData(const QMimeData *source) const;
|
||||
void insertFromMimeData(const QMimeData *source);
|
||||
QMimeData *createMimeDataFromSelection() const;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
#include "pickcolorwidget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QDebug>
|
||||
|
||||
#include "utils/global.h"
|
||||
#include "service/colorpickerinterface.h"
|
||||
|
||||
const QSize PICKCOLOR_WIDGET_SIZE = QSize(222, 217);
|
||||
|
||||
PickColorWidget::PickColorWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
DRAW_THEME_INIT_WIDGET("PickColorWidget");
|
||||
setFixedSize(222, 217);
|
||||
QLabel* titleLabel = new QLabel(this);
|
||||
titleLabel->setText("RGB");
|
||||
titleLabel->setObjectName("TitleLabel");
|
||||
|
||||
m_redEditLabel = new EditLabel(this);
|
||||
m_redEditLabel->setTitle("R");
|
||||
m_redEditLabel->setEditText("255");
|
||||
connect(m_redEditLabel, &EditLabel::editTextChanged,
|
||||
this, &PickColorWidget::updateColor);
|
||||
|
||||
m_greenEditLabel = new EditLabel(this);
|
||||
m_greenEditLabel->setTitle("G");
|
||||
m_greenEditLabel->setEditText("255");
|
||||
connect(m_greenEditLabel, &EditLabel::editTextChanged,
|
||||
this, &PickColorWidget::updateColor);
|
||||
|
||||
m_blueEditLabel = new EditLabel(this);
|
||||
m_blueEditLabel->setTitle("B");
|
||||
m_blueEditLabel->setEditText("255");
|
||||
connect(m_blueEditLabel, &EditLabel::editTextChanged,
|
||||
this, &PickColorWidget::updateColor);
|
||||
|
||||
m_picker = new QPushButton(this);
|
||||
m_picker->setFixedSize(24, 24);
|
||||
m_picker->setObjectName("PickerBtn");
|
||||
m_picker->setIcon(QIcon(":/images/resources/icons/picker.svg"));
|
||||
QHBoxLayout* rgbLayout = new QHBoxLayout;
|
||||
rgbLayout->setMargin(0);
|
||||
rgbLayout->setSpacing(0);
|
||||
rgbLayout->addWidget(titleLabel);
|
||||
rgbLayout->addSpacing(25);
|
||||
rgbLayout->addWidget(m_redEditLabel);
|
||||
rgbLayout->addWidget(m_greenEditLabel);
|
||||
rgbLayout->addWidget(m_blueEditLabel);
|
||||
rgbLayout->addSpacing(4);
|
||||
rgbLayout->addWidget(m_picker);
|
||||
m_colorSlider = new ColorSlider(this);
|
||||
m_colorSlider->setObjectName("ColorfulSlider");
|
||||
m_colorSlider->setFixedSize(222, 14);
|
||||
// m_colorSlider->setMinimum(0);
|
||||
// m_colorSlider->setMaximum(355);
|
||||
|
||||
m_colorLabel = new ColorLabel(this);
|
||||
m_colorLabel->setFixedSize(222, 136);
|
||||
connect(m_colorSlider, &ColorSlider::valueChanged, m_colorLabel, [=](int val){
|
||||
m_colorLabel->setHue(val);
|
||||
});
|
||||
connect(m_colorLabel, &ColorLabel::pickedColor, this, [=](QColor color){
|
||||
setRgbValue(color, true);
|
||||
});
|
||||
connect(m_picker, &QPushButton::clicked, this, [=]{
|
||||
ColorPickerInterface* cp = new ColorPickerInterface("com.deepin.Picker",
|
||||
"/com/deepin/Picker", QDBusConnection::sessionBus(), this);
|
||||
cp->StartPick(QString("%1").arg(qApp->applicationPid()));
|
||||
connect(cp, &ColorPickerInterface::colorPicked, this, [=](QString uuid,
|
||||
QString colorName){
|
||||
if (uuid == QString("%1").arg(qApp->applicationPid())) {
|
||||
setRgbValue(QColor(colorName), true);
|
||||
}
|
||||
m_picker->setChecked(false);
|
||||
cp->deleteLater();
|
||||
});
|
||||
});
|
||||
|
||||
QVBoxLayout* mLayout = new QVBoxLayout;
|
||||
mLayout->setMargin(0);
|
||||
mLayout->setSpacing(0);
|
||||
mLayout->addSpacing(16);
|
||||
mLayout->addLayout(rgbLayout);
|
||||
mLayout->addSpacing(10);
|
||||
mLayout->addWidget(m_colorLabel, 0, Qt::AlignCenter);
|
||||
mLayout->addWidget(m_colorSlider, 0, Qt::AlignCenter);
|
||||
setLayout(mLayout);
|
||||
}
|
||||
|
||||
void PickColorWidget::setRgbValue(QColor color, bool isPicked)
|
||||
{
|
||||
m_redEditLabel->setEditText(QString("%1").arg(color.red()));
|
||||
m_greenEditLabel->setEditText(QString("%1").arg(color.green()));
|
||||
m_blueEditLabel->setEditText(QString("%1").arg(color.blue()));
|
||||
|
||||
if (isPicked)
|
||||
emit pickedColor(color);
|
||||
}
|
||||
|
||||
void PickColorWidget::updateColor()
|
||||
{
|
||||
int r = m_redEditLabel->editText().toInt();
|
||||
int g = m_greenEditLabel->editText().toInt();
|
||||
int b = m_blueEditLabel->editText().toInt();
|
||||
|
||||
if (QColor(r, g, b).isValid())
|
||||
{
|
||||
emit pickedColor(QColor(r, g, b));
|
||||
}
|
||||
}
|
||||
|
||||
void PickColorWidget::setPickedColor(bool picked)
|
||||
{
|
||||
m_colorLabel->setPickColor(picked);
|
||||
}
|
||||
|
||||
PickColorWidget::~PickColorWidget()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef PICKCOLORWIDGET_H
|
||||
#define PICKCOLORWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "editlabel.h"
|
||||
#include "colorlabel.h"
|
||||
#include "colorslider.h"
|
||||
|
||||
class PickColorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PickColorWidget(QWidget* parent);
|
||||
~PickColorWidget();
|
||||
|
||||
void setRgbValue(QColor color, bool isPicked = false);
|
||||
void updateColor();
|
||||
void setPickedColor(bool picked);
|
||||
|
||||
signals:
|
||||
void pickedColor(QColor color);
|
||||
|
||||
private:
|
||||
EditLabel* m_redEditLabel;
|
||||
EditLabel* m_greenEditLabel;
|
||||
EditLabel* m_blueEditLabel;
|
||||
QPushButton* m_picker;
|
||||
ColorLabel* m_colorLabel;
|
||||
ColorSlider* m_colorSlider;
|
||||
};
|
||||
|
||||
#endif // PICKCOLORWIDGET_H
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "resizelabel.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
ResizeLabel::ResizeLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
|
||||
void ResizeLabel::paintResizeLabel(bool drawing, FourPoints fpoints)
|
||||
{
|
||||
if (drawing)
|
||||
{
|
||||
this->show();
|
||||
} else {
|
||||
this->hide();
|
||||
}
|
||||
m_drawArtboard = drawing;
|
||||
m_artboardMPoints = fpoints;
|
||||
update();
|
||||
}
|
||||
|
||||
ResizeLabel::~ResizeLabel()
|
||||
{
|
||||
}
|
||||
|
||||
void ResizeLabel::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
if (!m_drawArtboard)
|
||||
return;
|
||||
|
||||
else {
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing
|
||||
| QPainter::SmoothPixmapTransform);
|
||||
painter.setBrush(Qt::transparent);
|
||||
QPen dragPen;
|
||||
dragPen.setColor(QColor("#888888"));
|
||||
dragPen.setStyle(Qt::DashLine);
|
||||
painter.setPen(dragPen);
|
||||
m_artboardMPoints[3] = QPointF(std::max(m_artboardMPoints[3].x(),
|
||||
m_artboardMPoints[0].x() + 20), std::max(m_artboardMPoints[3].y(),
|
||||
m_artboardMPoints[0].y() + 20));
|
||||
QRect rect = QRect(int(m_artboardMPoints[0].x()),
|
||||
int(m_artboardMPoints[0].y()),
|
||||
int(m_artboardMPoints[3].x() - m_artboardMPoints[0].x()),
|
||||
int(m_artboardMPoints[3].y() - m_artboardMPoints[0].y()));
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef RESIZELABEL_H
|
||||
#define RESIZELABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include "utils/shapesutils.h"
|
||||
|
||||
class ResizeLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ResizeLabel(QWidget* parent = 0);
|
||||
~ResizeLabel();
|
||||
|
||||
public slots:
|
||||
void paintResizeLabel(bool drawing, FourPoints fpoints);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e);
|
||||
|
||||
private:
|
||||
bool m_drawArtboard;
|
||||
FourPoints m_artboardMPoints;
|
||||
|
||||
};
|
||||
|
||||
#endif // RESIZELABEL_H
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef SEPERATORLINE_H
|
||||
#define SEPERATORLINE_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class SeperatorLine : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SeperatorLine(QWidget* parent = 0) {
|
||||
Q_UNUSED(parent);
|
||||
setFixedSize(1, 18);
|
||||
setStyleSheet("border: 1px solid rgba(0, 0, 0, 0.1);");
|
||||
}
|
||||
~SeperatorLine() {}
|
||||
|
||||
};
|
||||
#endif // SEPERATORLINE_H
|
||||
@@ -0,0 +1,130 @@
|
||||
#include "sliderlabel.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
|
||||
#include "utils/configsettings.h"
|
||||
|
||||
const int SLIDER_WIDTH = 180;
|
||||
const QSize SLIDER_WIDTH_SIZE = QSize(222, 24);
|
||||
Slider::Slider(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setStyleSheet("Slider{"
|
||||
"border: 1px solid rgba(0, 0, 0, 26);"
|
||||
"border-radius: 3px; "
|
||||
"}");
|
||||
|
||||
setMinimumWidth(160);
|
||||
m_slider = new QSlider(Qt::Horizontal,this);
|
||||
m_slider->setMinimum(0);
|
||||
m_slider->setMaximum(100);
|
||||
m_slider->setValue(100);
|
||||
m_slider->setFixedWidth(127);
|
||||
m_valueLabel = new QLabel(this);
|
||||
m_valueLabel->setObjectName("ValueLabel");
|
||||
m_valueLabel->setStyleSheet("QLabel#ValueLabel{"
|
||||
"color: #303030;"
|
||||
"font-size: 11px;}");
|
||||
m_valueLabel->setText("100%");
|
||||
|
||||
QHBoxLayout* mLayout = new QHBoxLayout(this);
|
||||
mLayout->setMargin(0);
|
||||
mLayout->setSpacing(0);
|
||||
mLayout->addSpacing(1);
|
||||
mLayout->addWidget(m_slider);
|
||||
mLayout->addSpacing(4);
|
||||
mLayout->addWidget(m_valueLabel);
|
||||
mLayout->addSpacing(4);
|
||||
setLayout(mLayout);
|
||||
connect(m_slider, &QSlider::valueChanged, this, [=](int value){
|
||||
emit valueChanged(value);
|
||||
m_valueLabel->setText(QString("%1%").arg(value));
|
||||
});
|
||||
}
|
||||
|
||||
void Slider::setAlphaValue(int value)
|
||||
{
|
||||
qDebug() << "value..." << value;
|
||||
m_valueLabel->setText(QString("%1%").arg(value));
|
||||
m_slider->setValue(value);
|
||||
}
|
||||
|
||||
int Slider::alphaValue()
|
||||
{
|
||||
return m_slider->value();
|
||||
}
|
||||
|
||||
Slider::~Slider() {}
|
||||
|
||||
SliderLabel::SliderLabel(QString text, DrawStatus status,
|
||||
MiddleWidgetStatus widgetStatus, QWidget* parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
m_text = text;
|
||||
m_drawStatus = status;
|
||||
setFixedSize(SLIDER_WIDTH_SIZE);
|
||||
|
||||
m_titleLabel = new QLabel(this);
|
||||
m_titleLabel->setFixedWidth(43);
|
||||
m_titleLabel->setObjectName("TitleLabel");
|
||||
m_titleLabel->setStyleSheet("QLabel#TitleLabel {"
|
||||
"color: #626262;"
|
||||
"font-size: 11px;"
|
||||
"}");
|
||||
m_slider = new Slider(this);
|
||||
|
||||
updateDrawStatus(status, widgetStatus);
|
||||
m_titleLabel->setText(m_text);
|
||||
|
||||
QHBoxLayout* mLayout = new QHBoxLayout(this);
|
||||
mLayout->setMargin(0);
|
||||
mLayout->setSpacing(0);
|
||||
mLayout->addWidget(m_titleLabel);
|
||||
mLayout->addSpacing(5);
|
||||
mLayout->addWidget(m_slider);
|
||||
setLayout(mLayout);
|
||||
|
||||
connect(m_slider, &Slider::valueChanged, this, &SliderLabel::alphaChanged);
|
||||
}
|
||||
|
||||
int SliderLabel::alpha()
|
||||
{
|
||||
return m_slider->alphaValue();
|
||||
}
|
||||
|
||||
void SliderLabel::setAlpha(int val)
|
||||
{
|
||||
m_slider->setAlphaValue(val);
|
||||
}
|
||||
|
||||
void SliderLabel::updateDrawStatus(DrawStatus status,
|
||||
MiddleWidgetStatus widgetStatus)
|
||||
{
|
||||
int colorAlpha;
|
||||
m_drawStatus = status;
|
||||
m_widgetStatus = widgetStatus;
|
||||
|
||||
if (widgetStatus != MiddleWidgetStatus::DrawText)
|
||||
{
|
||||
if (m_drawStatus == DrawStatus::Fill)
|
||||
{
|
||||
colorAlpha = ConfigSettings::instance()->value("common", "fillColor_alpha").toInt();
|
||||
} else
|
||||
{
|
||||
colorAlpha = ConfigSettings::instance()->value("common", "strokeColor_alpha").toInt();
|
||||
}
|
||||
} else {
|
||||
colorAlpha = ConfigSettings::instance()->value("text", "fillColor_alpha").toInt();
|
||||
}
|
||||
|
||||
m_slider->setAlphaValue(colorAlpha);
|
||||
}
|
||||
|
||||
void SliderLabel::setTitle(const QString &text) {
|
||||
m_text = text;
|
||||
m_titleLabel->setText(m_text);
|
||||
}
|
||||
|
||||
SliderLabel::~SliderLabel() {}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef SLIDERLABEL_H
|
||||
#define SLIDERLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
#include <QWidget>
|
||||
|
||||
#include "colorslider.h"
|
||||
//#include "utils/baseutils.h"
|
||||
|
||||
class Slider : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Slider(QWidget* parent);
|
||||
~Slider();
|
||||
|
||||
void setAlphaValue(int value);
|
||||
int alphaValue();
|
||||
|
||||
signals:
|
||||
void valueChanged(int value);
|
||||
|
||||
private:
|
||||
QSlider* m_slider;
|
||||
QLabel* m_valueLabel;
|
||||
};
|
||||
|
||||
class SliderLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderLabel(QString text, DrawStatus status,
|
||||
MiddleWidgetStatus widgetStatus, QWidget* parent = 0);
|
||||
~SliderLabel();
|
||||
|
||||
void setTitle(const QString &text);
|
||||
int alpha ();
|
||||
void updateDrawStatus(DrawStatus status,
|
||||
MiddleWidgetStatus widgetStatus);
|
||||
void setAlpha(int val);
|
||||
|
||||
signals:
|
||||
void alphaChanged(int value);
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
DrawStatus m_drawStatus;
|
||||
MiddleWidgetStatus m_widgetStatus;
|
||||
|
||||
QLabel* m_titleLabel;
|
||||
Slider* m_slider;
|
||||
};
|
||||
|
||||
#endif // SLIDERLABEL_H
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "textfontlabel.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "fontsizelineedit.h"
|
||||
#include "toolbutton.h"
|
||||
#include "utils/global.h"
|
||||
#include "utils/configsettings.h"
|
||||
|
||||
const int LINEEDIT_WIDTH = 64;
|
||||
const int BUTTON_WIDTH = 25;
|
||||
const int BUTTON_HEIGHT = 26;
|
||||
|
||||
TextFontLabel::TextFontLabel(QWidget *parent)
|
||||
: QLabel(parent),
|
||||
m_fontsize(12)
|
||||
{
|
||||
DRAW_THEME_INIT_WIDGET("TextFontLabel");
|
||||
|
||||
this->setObjectName("TextFontLabel");
|
||||
this->setFixedSize(LINEEDIT_WIDTH + BUTTON_WIDTH*2,
|
||||
BUTTON_HEIGHT);
|
||||
FontsizeLineEdit* fontEdit = new FontsizeLineEdit(this);
|
||||
fontEdit->setObjectName("FontsizeEdit");
|
||||
fontEdit->setFixedSize(LINEEDIT_WIDTH, BUTTON_HEIGHT - 2);
|
||||
m_fontsize = ConfigSettings::instance()->value("text", "fontsize").toInt();
|
||||
fontEdit->setText(QString("%1").arg(m_fontsize));
|
||||
|
||||
connect(ConfigSettings::instance(), &ConfigSettings::configChanged, this, [=](
|
||||
const QString &group, const QString &key){
|
||||
if (group == "text" && key == "fontsize")
|
||||
{
|
||||
m_fontsize = ConfigSettings::instance()->value(group, key).toInt();
|
||||
fontEdit->setText(QString("%1").arg(m_fontsize));
|
||||
}
|
||||
});
|
||||
connect(fontEdit, &QLineEdit::editingFinished, this, [=]{
|
||||
int fontSize = fontEdit->text().toInt();
|
||||
fontSize = std::max(8, fontSize);
|
||||
fontEdit->setText(QString("%1").arg(fontSize));
|
||||
m_fontsize = fontSize;
|
||||
ConfigSettings::instance()->setValue("text", "fontsize", fontSize);
|
||||
});
|
||||
connect(fontEdit, &FontsizeLineEdit::addSize, this, [=]{
|
||||
int fontSize = fontEdit->text().toInt();
|
||||
fontSize = std::max(8, fontSize + 1);
|
||||
m_fontsize = fontSize;
|
||||
fontEdit->setText(QString("%1").arg(fontSize));
|
||||
});
|
||||
connect(fontEdit, &FontsizeLineEdit::reduceSize, this, [=]{
|
||||
int fontSize = fontEdit->text().toInt();
|
||||
fontSize = std::max(8, fontSize - 1);
|
||||
m_fontsize = fontSize;
|
||||
fontEdit->setText(QString("%1").arg(fontSize));
|
||||
});
|
||||
|
||||
ToolButton* addBtn = new ToolButton(this);
|
||||
addBtn->setObjectName("AddFontsizeBtn");
|
||||
addBtn->setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
addBtn->setAutoRepeat(true);
|
||||
ToolButton* reduceBtn = new ToolButton(this);
|
||||
reduceBtn->setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
reduceBtn->setObjectName("ReduceFontsizeBtn");
|
||||
reduceBtn->setAutoRepeat(true);
|
||||
|
||||
QHBoxLayout* hLayout = new QHBoxLayout(this);
|
||||
hLayout->setMargin(0);
|
||||
hLayout->setSpacing(0);
|
||||
hLayout->addWidget(fontEdit, 0, Qt::AlignCenter);
|
||||
hLayout->addSpacing(0);
|
||||
hLayout->addWidget(addBtn, 0, Qt::AlignCenter);
|
||||
hLayout->addSpacing(0);
|
||||
hLayout->addWidget(reduceBtn, 0, Qt::AlignCenter);
|
||||
setLayout(hLayout);
|
||||
|
||||
connect(addBtn, &ToolButton::pressed, this, [=]{
|
||||
m_fontsize += 1;
|
||||
fontEdit->setText(QString("%1").arg(m_fontsize));
|
||||
ConfigSettings::instance()->setValue("text", "fontsize", m_fontsize);
|
||||
});
|
||||
|
||||
connect(reduceBtn, &ToolButton::pressed, this, [=]{
|
||||
m_fontsize -= 1;
|
||||
m_fontsize = std::max(8, m_fontsize);
|
||||
fontEdit->setText(QString("%1").arg(m_fontsize));
|
||||
ConfigSettings::instance()->setValue("text", "fontsize", m_fontsize);
|
||||
});
|
||||
}
|
||||
|
||||
TextFontLabel::~TextFontLabel()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef TEXTFONTLABEL_H
|
||||
#define TEXTFONTLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "toolbutton.h"
|
||||
|
||||
class TextFontLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextFontLabel(QWidget* parent = 0);
|
||||
~TextFontLabel();
|
||||
|
||||
private:
|
||||
int m_fontsize;
|
||||
};
|
||||
|
||||
#endif // TEXTFONTLABEL_H
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "tipslabel.h"
|
||||
|
||||
TipsLabel::TipsLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setObjectName("TipsLabel");
|
||||
setStyleSheet("QLabel#TipsLabel{"
|
||||
"background-color: rgba(255, 255, 255, 153);"
|
||||
"border-radius: 3px;"
|
||||
"border: 1px solid rgba(0, 0, 0, 13);}");
|
||||
setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
TipsLabel::~TipsLabel()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef TIPSLABEL_H
|
||||
#define TIPSLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class TipsLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TipsLabel(QWidget* parent = 0);
|
||||
~TipsLabel();
|
||||
|
||||
};
|
||||
|
||||
#endif // TIPSLABEL_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef TOOLBUTTON_H
|
||||
#define TOOLBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class ToolButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ToolButton(QWidget* parent = 0) {
|
||||
Q_UNUSED(parent);
|
||||
setFixedSize(24, 24);
|
||||
setCheckable(true);
|
||||
}
|
||||
|
||||
ToolButton(QString text, QWidget* parent = 0) {
|
||||
Q_UNUSED(parent);
|
||||
setFixedSize(24, 24);
|
||||
setCheckable(true);
|
||||
setText(text);
|
||||
}
|
||||
~ToolButton() {}
|
||||
};
|
||||
|
||||
#endif // TOOLBUTTON_H
|
||||
@@ -0,0 +1,420 @@
|
||||
#include "treemodelcomposeelement.h"
|
||||
#include "treeitem.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
|
||||
TreeModelComposeElement::TreeModelComposeElement(const QStringList &headers, const QString &data, QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
QVector<QVariant> rootData;
|
||||
foreach (QString header, headers)
|
||||
rootData << header;
|
||||
|
||||
rootItem = new TreeItem(rootData);
|
||||
//setupModelData(data.split(QString("\n")), rootItem);
|
||||
|
||||
// Insertar 20 filas vacias por defecto:
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
rootItem->insertChildren(rootItem->childCount(), 1, rootItem->columnCount());
|
||||
for (int column = 0; column < rootItem->columnCount(); ++column)
|
||||
rootItem->child(rootItem->childCount() - 1)->setData(column, QVariant());
|
||||
}
|
||||
}
|
||||
|
||||
TreeModelComposeElement::~TreeModelComposeElement()
|
||||
{
|
||||
delete rootItem;
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
int TreeModelComposeElement::columnCount(const QModelIndex & /* parent */) const
|
||||
{
|
||||
return rootItem->columnCount();
|
||||
}
|
||||
//! [2]
|
||||
|
||||
QVariant TreeModelComposeElement::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
TreeItem *item = getItem(index);
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
{
|
||||
if(item->data(7).toString().isEmpty())
|
||||
{
|
||||
//return data(index, role).toString();
|
||||
return item->data(index.column()).toString();
|
||||
}
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
{
|
||||
float value = 0;
|
||||
|
||||
if(item->data(index.column()).isValid())
|
||||
{
|
||||
value = item->data(index.column()).toFloat();
|
||||
}
|
||||
|
||||
QLocale locale = QLocale("es_ES");
|
||||
QString s = locale.toString(value, 'f', 2);
|
||||
return s;
|
||||
}
|
||||
default:
|
||||
return item->data(index.column()).toString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::ForegroundRole:
|
||||
if(index.column() == 0)
|
||||
return QVariant::fromValue(QColor(Qt::blue));
|
||||
else
|
||||
return QVariant();
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
switch (index.column())
|
||||
{
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
{
|
||||
return int(Qt::AlignRight | Qt::AlignTop);
|
||||
}
|
||||
default:
|
||||
return int(Qt::AlignLeft | Qt::AlignTop);
|
||||
}
|
||||
|
||||
case Qt::FontRole:
|
||||
if(item->childCount() > 0)
|
||||
{
|
||||
QFont font = QFont("Helvetica", 9, QFont::Bold);
|
||||
return QVariant::fromValue(font);
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
|
||||
case Qt::SizeHintRole:
|
||||
{
|
||||
int he = 24;
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
return QSize(30, he);
|
||||
case 1:
|
||||
return QSize(70, he);
|
||||
case 2:
|
||||
case 3:
|
||||
return QSize(150, he);
|
||||
case 4:
|
||||
case 5:
|
||||
return QSize(50, he);
|
||||
case 6:
|
||||
return QSize(40, he);
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
return QSize(50, he);
|
||||
case 12:
|
||||
return QSize(70, he);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
/*
|
||||
0 Sin clasificar
|
||||
1 Mano de obra
|
||||
2 Maquinaria
|
||||
3 Materiales
|
||||
4 Componentes adicionales de residuo
|
||||
5 Clasificación de residuo
|
||||
*/
|
||||
|
||||
if(index.column() == 0)
|
||||
{
|
||||
if(item->data(7).toString() == "CO") // Compuesto
|
||||
{
|
||||
return QIcon(":/resources/icons/box.svg");
|
||||
}
|
||||
else if(item->data(7).toString() == "MT") // Materiales
|
||||
{
|
||||
return QIcon(":/resources/icons/blocks.svg");
|
||||
}
|
||||
else if(item->data(7).toString() == "MO") // Mano de obra
|
||||
{
|
||||
return QIcon(":/resources/icons/helmet.svg");
|
||||
}
|
||||
else if(item->data(7).toString() == "MQ") // Maquinaria
|
||||
{
|
||||
return QIcon(":/resources/icons/gear.svg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
//! [3]
|
||||
Qt::ItemFlags TreeModelComposeElement::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
//case 5:
|
||||
{
|
||||
flags |= Qt::ItemIsEditable;
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
TreeItem *TreeModelComposeElement::getItem(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
return rootItem;
|
||||
}
|
||||
//! [4]
|
||||
|
||||
QVariant TreeModelComposeElement::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
//! [5]
|
||||
QModelIndex TreeModelComposeElement::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid() && parent.column() != 0)
|
||||
return QModelIndex();
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
TreeItem *parentItem = getItem(parent);
|
||||
TreeItem *childItem = parentItem->child(row);
|
||||
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
//! [6]
|
||||
|
||||
bool TreeModelComposeElement::insertColumns(int position, int columns, const QModelIndex &parent)
|
||||
{
|
||||
bool success;
|
||||
|
||||
beginInsertColumns(parent, position, position + columns - 1);
|
||||
success = rootItem->insertColumns(position, columns);
|
||||
endInsertColumns();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool TreeModelComposeElement::insertRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
TreeItem *parentItem = getItem(parent);
|
||||
bool success;
|
||||
|
||||
beginInsertRows(parent, position, position + rows - 1);
|
||||
success = parentItem->insertChildren(position, rows, rootItem->columnCount());
|
||||
endInsertRows();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
//! [7]
|
||||
QModelIndex TreeModelComposeElement::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
TreeItem *childItem = getItem(index);
|
||||
TreeItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->childNumber(), 0, parentItem);
|
||||
}
|
||||
//! [7]
|
||||
|
||||
bool TreeModelComposeElement::removeColumns(int position, int columns, const QModelIndex &parent)
|
||||
{
|
||||
bool success;
|
||||
|
||||
beginRemoveColumns(parent, position, position + columns - 1);
|
||||
success = rootItem->removeColumns(position, columns);
|
||||
endRemoveColumns();
|
||||
|
||||
if (rootItem->columnCount() == 0)
|
||||
removeRows(0, rowCount());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool TreeModelComposeElement::removeRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
TreeItem *parentItem = getItem(parent);
|
||||
bool success = true;
|
||||
|
||||
beginRemoveRows(parent, position, position + rows - 1);
|
||||
success = parentItem->removeChildren(position, rows);
|
||||
endRemoveRows();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
//! [8]
|
||||
int TreeModelComposeElement::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
TreeItem *parentItem = getItem(parent);
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
//! [8]
|
||||
|
||||
bool TreeModelComposeElement::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (role != Qt::EditRole)
|
||||
return false;
|
||||
|
||||
TreeItem *item = getItem(index);
|
||||
bool result = item->setData(index.column(), value);
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 2:
|
||||
item->setData(3, value);
|
||||
calculateRow(item);
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
emit dataChanged(index, index, {role});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void TreeModelComposeElement::calculateRow(TreeItem *item)
|
||||
{
|
||||
float cu = item->data(2).toFloat();
|
||||
float ct = item->data(3).toFloat();
|
||||
float pcu = item->data(5).toFloat();
|
||||
float pct = ct * pcu;
|
||||
|
||||
item->setData(6, pct);
|
||||
}
|
||||
|
||||
bool TreeModelComposeElement::setHeaderData(int section, Qt::Orientation orientation,
|
||||
const QVariant &value, int role)
|
||||
{
|
||||
if (role != Qt::EditRole || orientation != Qt::Horizontal)
|
||||
return false;
|
||||
|
||||
bool result = rootItem->setData(section, value);
|
||||
|
||||
if (result)
|
||||
emit headerDataChanged(orientation, section, section);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void TreeModelComposeElement::setupModelData(const QStringList &lines, TreeItem *parent)
|
||||
{
|
||||
QList<TreeItem*> parents;
|
||||
QList<int> indentations;
|
||||
parents << parent;
|
||||
indentations << 0;
|
||||
|
||||
int number = 0;
|
||||
|
||||
while (number < lines.count())
|
||||
{
|
||||
int position = 0;
|
||||
while (position < lines[number].length())
|
||||
{
|
||||
if (lines[number].at(position) != ' ')
|
||||
break;
|
||||
++position;
|
||||
}
|
||||
|
||||
QString lineData = lines[number].mid(position).trimmed();
|
||||
|
||||
if (!lineData.isEmpty())
|
||||
{
|
||||
// Read the column data from the rest of the line.
|
||||
QStringList columnStrings = lineData.split("\t", Qt::SkipEmptyParts);
|
||||
QVector<QVariant> columnData;
|
||||
for (int column = 0; column < columnStrings.count(); ++column)
|
||||
columnData << columnStrings[column];
|
||||
|
||||
if (position > indentations.last())
|
||||
{
|
||||
// The last child of the current parent is now the new parent
|
||||
// unless the current parent has no children.
|
||||
|
||||
if (parents.last()->childCount() > 0)
|
||||
{
|
||||
parents << parents.last()->child(parents.last()->childCount()-1);
|
||||
indentations << position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (position < indentations.last() && parents.count() > 0)
|
||||
{
|
||||
parents.pop_back();
|
||||
indentations.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Append a new item to the current parent's list of children.
|
||||
TreeItem *parent = parents.last();
|
||||
parent->insertChildren(parent->childCount(), 1, rootItem->columnCount());
|
||||
for (int column = 0; column < columnData.size(); ++column)
|
||||
parent->child(parent->childCount() - 1)->setData(column, columnData[column]);
|
||||
}
|
||||
|
||||
++number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef TREEMODELCOMPOSEELEMENT_H
|
||||
#define TREEMODELCOMPOSEELEMENT_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QModelIndex>
|
||||
#include <QVariant>
|
||||
|
||||
class TreeItem;
|
||||
|
||||
class TreeModelComposeElement : public QAbstractItemModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TreeModelComposeElement(const QStringList &headers, const QString &data, QObject *parent = nullptr);
|
||||
~TreeModelComposeElement() override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
private:
|
||||
void setupModelData(const QStringList &lines, TreeItem *parent);
|
||||
TreeItem *getItem(const QModelIndex &index) const;
|
||||
TreeItem *rootItem;
|
||||
void calculateRow(TreeItem *item);
|
||||
};
|
||||
|
||||
#endif // TREEMODELCOMPOSEELEMENT_H
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "widgetcomboboxpopuptable.h"
|
||||
#include "ui_widgetcomboboxpopuptable.h"
|
||||
#include "frameless.h"
|
||||
#include "mapplication.h"
|
||||
|
||||
|
||||
//#include <QScreen>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QScreen>
|
||||
#include <QSqlQueryModel>
|
||||
|
||||
widgetComboboxPopupTable::widgetComboboxPopupTable(QWidget *parent) :
|
||||
QWidget(parent)//,ui(new Ui::widgetComboboxPopupTable)
|
||||
{
|
||||
//setWindowFlags(Qt::FramelessWindowHint);
|
||||
setupUi(this);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect;
|
||||
windowShadow->setBlurRadius(9.0);
|
||||
windowShadow->setColor(palette().color(QPalette::Highlight));
|
||||
windowShadow->setOffset(0.0);
|
||||
setGraphicsEffect(windowShadow);
|
||||
*/
|
||||
|
||||
mMultiselect = false;
|
||||
|
||||
//mModel = new QSqlQueryModel(this);
|
||||
connect(dApp, &QApplication::focusChanged, this, &widgetComboboxPopupTable::on_focusChanged);
|
||||
|
||||
FrameLess(this);
|
||||
}
|
||||
|
||||
widgetComboboxPopupTable::~widgetComboboxPopupTable()
|
||||
{
|
||||
delete mModel;
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::setModel(QSqlQueryModel *aModel)
|
||||
{
|
||||
mModel = aModel;
|
||||
tableView->setModel(mModel);
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::setQueryEXEC(QString command)
|
||||
{
|
||||
dApp->Enterprise().open();
|
||||
mModel->setQuery(command, dApp->Enterprise());
|
||||
dApp->Enterprise().close();
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::on_tableView_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
SelectValues();
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::on_buttonSelect_released()
|
||||
{
|
||||
SelectValues();
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::SelectValues()
|
||||
{
|
||||
QStringList values;
|
||||
//QModelIndex index = tableView->currentIndex();
|
||||
|
||||
QModelIndexList indexList = tableView->selectionModel()->selectedRows(2);
|
||||
int row;
|
||||
foreach (QModelIndex index, indexList)
|
||||
{
|
||||
row = index.row();
|
||||
values << index.data().toString();
|
||||
}
|
||||
|
||||
emit onSelect(values);
|
||||
hide();
|
||||
}
|
||||
|
||||
void widgetComboboxPopupTable::on_focusChanged(QWidget *old, QWidget *now)
|
||||
{
|
||||
Q_UNUSED(old);
|
||||
if (now != this && !this->isAncestorOf(now))
|
||||
{
|
||||
hide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef WIDGETCOMBOBOXPOPUPTABLE_H
|
||||
#define WIDGETCOMBOBOXPOPUPTABLE_H
|
||||
#include "ui_widgetcomboboxpopuptable.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QSqlQueryModel;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class widgetComboboxPopupTable;
|
||||
}
|
||||
|
||||
class widgetComboboxPopupTable : public QWidget, public Ui::widgetComboboxPopupTable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit widgetComboboxPopupTable(QWidget *parent = 0);
|
||||
~widgetComboboxPopupTable();
|
||||
|
||||
void setModel(QSqlQueryModel *aModel);
|
||||
void setQueryEXEC(QString command);
|
||||
|
||||
private slots:
|
||||
void on_tableView_doubleClicked(const QModelIndex &index);
|
||||
void on_buttonSelect_released();
|
||||
void on_focusChanged(QWidget *old, QWidget *now);
|
||||
|
||||
private:
|
||||
//Ui::widgetComboboxPopupTable *ui;
|
||||
QSqlQueryModel *mModel;
|
||||
bool mMultiselect;
|
||||
void SelectValues();
|
||||
|
||||
signals:
|
||||
void onSelect(QStringList aList);
|
||||
};
|
||||
|
||||
#endif // WIDGETCOMBOBOXPOPUPTABLE_H
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>widgetComboboxPopupTable</class>
|
||||
<widget class="QWidget" name="widgetComboboxPopupTable">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>287</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonNew">
|
||||
<property name="text">
|
||||
<string>Nuevo</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../editabletreemodel.qrc">
|
||||
<normaloff>:/resources/icons/add-file.svg</normaloff>:/resources/icons/add-file.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonEdit">
|
||||
<property name="text">
|
||||
<string>Editar</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../editabletreemodel.qrc">
|
||||
<normaloff>:/resources/icons/pencil(1).svg</normaloff>:/resources/icons/pencil(1).svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonSelect">
|
||||
<property name="text">
|
||||
<string>Seleccionar</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../editabletreemodel.qrc">
|
||||
<normaloff>:/resources/icons/tick.svg</normaloff>:/resources/icons/tick.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../editabletreemodel.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,3 @@
|
||||
<RCC>
|
||||
<qresource prefix="/"/>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user