You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
197 lines
4.8 KiB
C++
197 lines
4.8 KiB
C++
#ifndef SCALE_H
|
|
#define SCALE_H
|
|
|
|
//Qt
|
|
#include <QColor>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QPaintEvent>
|
|
#include <QVector>
|
|
#include <QPainterPathStroker>
|
|
#include <QPen>
|
|
#include <QWidget>
|
|
#include <QPaintEngine>
|
|
#include <QPoint>
|
|
#include <QRect>
|
|
#include <QThread>
|
|
|
|
class Scale
|
|
{
|
|
public:
|
|
Scale(int scaleLength,int scaleCount,int width,int height,const QPoint& topleft,const QPoint& bottomright){
|
|
_scaleLength = scaleLength;
|
|
_scaleCount = scaleCount;
|
|
_topLeft = topleft;
|
|
_bottomRight = bottomright;
|
|
_scaleColor = QColor(192,192,192);
|
|
_scalex = 1;
|
|
_scaley = 1;
|
|
_width = width;
|
|
_height = height;
|
|
}
|
|
Scale(){
|
|
_scaleLength = 6;
|
|
_scaleCount = 8;
|
|
_topLeft = QPoint(90,90);
|
|
_bottomRight = QPoint(300,300);
|
|
_scaleColor = QColor(192,192,192);
|
|
_scalex = 1;
|
|
_scaley = 1;
|
|
_width = 0;
|
|
_height = 0;
|
|
}
|
|
|
|
void paint(QPixmap& w, QPaintEvent* event=nullptr){
|
|
_scaleCount = _scaleCount > 8? _scaleCount : 8;
|
|
QPainter painter;
|
|
painter.begin(&w);
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
painter.scale(_scalex,_scaley);
|
|
_rect = QRect(QPoint(_topLeft.x()/_scalex,_topLeft.y()/_scaley),QPoint(_bottomRight.x()/_scalex,_bottomRight.y()/_scaley));
|
|
painter.setPen(QPen(Qt::black, 0.8));
|
|
painter.setBrush(_scaleColor);
|
|
painter.drawRect(_rect);
|
|
int width = _rect.width();
|
|
int height = _rect.height();
|
|
int tmp = _scaleCount/2;
|
|
if(_width==0){
|
|
_width = width;
|
|
}
|
|
if(_height==0){
|
|
_height = height;
|
|
}
|
|
|
|
// 上
|
|
for (int i = 1; i < _scaleCount; ++i) {
|
|
int x = _rect.left() + (i * width / _scaleCount);
|
|
painter.drawLine(x, _rect.y(), x, _rect.y() - _scaleLength);
|
|
const QRect rectangle = QRect(QPoint(x-25, _rect.y()-50), QPoint(x+25, _rect.y()- _scaleLength));
|
|
painter.drawText(rectangle,Qt::AlignBottom,QString::number((i-tmp) * _width / _scaleCount));
|
|
}
|
|
|
|
// 下
|
|
for (int i = 1; i < _scaleCount; ++i) {
|
|
int x = _rect.left() + (i * width / _scaleCount);
|
|
painter.drawLine(x, _rect.y() + height, x, _rect.y() + height + _scaleLength);
|
|
const QRect rectangle = QRect(x, _rect.y() + height + _scaleLength,x, _rect.y() + height + 100);
|
|
painter.drawText(rectangle,Qt::AlignTop,QString::number((i-tmp) * _width / _scaleCount));
|
|
}
|
|
|
|
//左
|
|
for (int i = 1; i < _scaleCount; ++i) {
|
|
int y = _rect.top() + (i * height / _scaleCount);
|
|
painter.drawLine(_rect.x() - _scaleLength, y, _rect.x(), y);
|
|
const QRect rectangle = QRect(_rect.x() -_scaleLength-100, y, _rect.x() -_scaleLength, y);
|
|
painter.drawText(rectangle,Qt::AlignRight,QString::number((i-tmp) * _height / _scaleCount));
|
|
}
|
|
|
|
|
|
//右
|
|
for (int i = 1; i < _scaleCount; ++i) {
|
|
int y = _rect.top() + (i * height / _scaleCount);
|
|
painter.drawLine(_rect.x() + width, y, _rect.x() + width + _scaleLength, y);
|
|
const QRect rectangle = QRect(_rect.x() + width + _scaleLength, y, _rect.x() + width + _scaleLength+100, y);
|
|
painter.drawText(rectangle,Qt::AlignLeft,QString::number((i-tmp) * _height / _scaleCount));
|
|
}
|
|
painter.end();
|
|
|
|
}
|
|
|
|
int scaleLength() const{
|
|
return _scaleLength;
|
|
}
|
|
void setScaleLength(int scaleLength){
|
|
_scaleLength = scaleLength;
|
|
}
|
|
|
|
double scalex() const
|
|
{
|
|
return _scalex;
|
|
}
|
|
|
|
void setScalex(double scalex)
|
|
{
|
|
_scalex = scalex;
|
|
}
|
|
|
|
double scaley() const
|
|
{
|
|
return _scaley;
|
|
}
|
|
|
|
void setScaley(double scaley)
|
|
{
|
|
_scaley = scaley;
|
|
}
|
|
|
|
QRect rect() const{
|
|
return _rect;
|
|
}
|
|
|
|
QPoint topLeft() const
|
|
{
|
|
return _topLeft;
|
|
}
|
|
|
|
void setTopLeft(const QPoint &topLeft)
|
|
{
|
|
_topLeft = topLeft;
|
|
}
|
|
|
|
QPoint bottomRight() const
|
|
{
|
|
return _bottomRight;
|
|
}
|
|
|
|
void setBottomRight(const QPoint &bottomRight)
|
|
{
|
|
_bottomRight = bottomRight;
|
|
}
|
|
|
|
int width() const
|
|
{
|
|
return _width;
|
|
}
|
|
|
|
void setWidth(int width)
|
|
{
|
|
_width = width;
|
|
}
|
|
|
|
int height() const
|
|
{
|
|
return _height;
|
|
}
|
|
|
|
void setHeight(int height)
|
|
{
|
|
_height = height;
|
|
}
|
|
|
|
int scaleCount() const
|
|
{
|
|
return _scaleCount;
|
|
}
|
|
|
|
void setScaleCount(int scaleCount)
|
|
{
|
|
_scaleCount = scaleCount;
|
|
}
|
|
|
|
private:
|
|
int _scaleLength;
|
|
int _scaleCount;
|
|
QPoint _topLeft;
|
|
QPoint _bottomRight;
|
|
QRect _rect;
|
|
QColor _scaleColor;
|
|
double _scalex;
|
|
double _scaley;
|
|
int _width;
|
|
int _height;
|
|
|
|
};
|
|
|
|
#endif // SCALE_H
|
|
|