Стиль и направление текста

main
Артём Проскурнёв 3 years ago
parent 4bfe0a8d05
commit 2c93aefe72
  1. 14
      main.cpp
  2. 25
      qtsgraph.cpp
  3. 29
      qtsgraph.h

@ -11,7 +11,7 @@ int main(int argc, char *argv[])
* (int w = 640, int h = 480, int x = -1, int y = -1, QWidget *parent = nullptr)
* В случае отрицательного значения x или y, окно создаётся в центре экрана.
*/
QTSGraph w(800, 600);
QTSGraph w(600, 600);
w.show();
return a.exec();
@ -22,9 +22,17 @@ void QTSGraph::PaintBox()
// Начало рисования
SetColor(clGreen);
Line(0, 0, 800, 600);
Line(0, 0, 600, 600);
SetColor(0xFF0000);
Line(800, 0, 0, 600);
Line(600, 0, 0, 600);
Rectangle(0,0,600,600);
SetColor(clBlue);
SetTextStyle(0, 45, 10);
OutTextXY(30, 30, "Hello world!");
SetTextStyle(1, 0, 20);
OutTextXY(210, 50, "Hello world!");
SetTextStyle(2, 0, 30);
OutTextXY(160, 550, "Hello world!");
// Конец рисования
}

@ -66,6 +66,7 @@ QTSGraph::QTSGraph(int w, int h, int x, int y, QWidget *parent)
Canvas.fill(Qt::white);
QRgb DefaultColor = 0x00000000;
Pen = QPen(QBrush(QColor(DefaultColor)), 1);
Font = QFont();
Brush = QBrush(QColor(DefaultColor),Qt::NoBrush);
ResetInterval = 1000;
ResetTimer = new QTimer();
@ -102,7 +103,20 @@ void QTSGraph::OutTextXY(int x, int y, std::string caption)
{
QPainter painter(&Canvas);
painter.setPen(Pen);
painter.setFont(Font);
double r, b, sa, ca, sb, cb, xn, yn;
b = TextDirection*3.14159/180;
r = sqrt(x * x + y * y);
sa = y / r;
ca = x / r;
sb = sin(b);
cb = cos(b);
xn = r * (ca * cb - sa * sb);
yn = r * (sa * cb + sb * ca);
painter.translate(x - xn, y - yn);
painter.rotate(TextDirection);
painter.drawText(x, y, QString::fromStdString(caption));
//painter.rotate(-TextDirection);
update();
}
@ -157,6 +171,17 @@ void QTSGraph::SetPenWidth(int PenWidth)
Pen.setWidth(PenWidth);
}
void QTSGraph::SetTextStyle(int idFont, int Direction, int CharSize)
{
QString f;
if(idFont == 0) f = "serif";
else if(idFont == 1) f = "sans";
else if(idFont == 3) f = "mono";
TextDirection = Direction;
Font.setFamily(f);
Font.setPointSize(CharSize);
}
void QTSGraph::Line(int x1, int y1, int x2, int y2)
{
QPainter painter(&Canvas);

@ -50,6 +50,7 @@ along with Vesi. If not, see <http://www.gnu.org/licenses/>.
#include <QTime>
#include <string>
#include <QDebug>
#include <math.h>
#define clRed 0x00FF0000
#define clGreen 0x0000FF00
@ -110,26 +111,36 @@ public:
5 - DashDotDotLine
*/
void SetPenWidth(int PenWidth);
void SetTextStyle(int idFont, int Direction, int CharSize);
/*
0 - serif
1 - sans
2 - mono
*/
private slots:
void slotStartTimer();
void slotResetTimer();
void slotStartTimer();
private:
QPixmap Canvas;
QTimer *StartTimer;
QTimer *ResetTimer;
bool EventMouseClicked = false;
bool EventKeyPressed = false;
int IDPressedKey = -1;
void PaintBox();
int ResetInterval;
int TextDirection = 0;
QBrush Brush;
QPixmap Canvas;
QFont Font;
QPen Pen;
int ResetInterval;
QTimer *ResetTimer;
QTimer *StartTimer;
void PaintBox();
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
};

Loading…
Cancel
Save