├── doc ├── chart1.png ├── chart2.png └── qt_drawing_paper_editor_img.gif ├── main.cpp ├── .gitignore ├── mainwindow.h ├── LICENSE ├── QtDrawingPaperEditorDemo.pro ├── README.md ├── mainwindow.cpp └── views └── drawingpapereditor ├── drawingpapereditor.h └── drawingpapereditor.cpp /doc/chart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robert1207/QtDrawingPaperEditorDemo/HEAD/doc/chart1.png -------------------------------------------------------------------------------- /doc/chart2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robert1207/QtDrawingPaperEditorDemo/HEAD/doc/chart2.png -------------------------------------------------------------------------------- /doc/qt_drawing_paper_editor_img.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robert1207/QtDrawingPaperEditorDemo/HEAD/doc/qt_drawing_paper_editor_img.gif -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.dll 10 | *.dylib 11 | 12 | # Qt-es 13 | object_script.*.Release 14 | object_script.*.Debug 15 | *_plugin_import.cpp 16 | /.qmake.cache 17 | /.qmake.stash 18 | *.pro.user 19 | *.pro.user.* 20 | *.qbs.user 21 | *.qbs.user.* 22 | *.moc 23 | moc_*.cpp 24 | moc_*.h 25 | qrc_*.cpp 26 | ui_*.h 27 | *.qmlc 28 | *.jsc 29 | Makefile* 30 | *build-* 31 | 32 | # Qt unit tests 33 | target_wrapper.* 34 | 35 | # QtCreator 36 | *.autosave 37 | 38 | # QtCreator Qml 39 | *.qmlproject.user 40 | *.qmlproject.user.* 41 | 42 | # QtCreator CMake 43 | CMakeLists.txt.user* 44 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include "views/drawingpapereditor/drawingpapereditor.h" 11 | 12 | 13 | class MainWindow : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | MainWindow(QWidget *parent = nullptr); 19 | ~MainWindow(); 20 | 21 | private: 22 | void setupUi(QMainWindow *MainWindow); 23 | void retranslateUi(QMainWindow *MainWindow); 24 | 25 | private: 26 | 27 | 28 | QWidget *centralwidget; 29 | QMenuBar *menubar; 30 | QStatusBar *statusbar; 31 | }; 32 | #endif // MAINWINDOW_H 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Robert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QtDrawingPaperEditorDemo.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | mainwindow.cpp \ 21 | views/drawingpapereditor/drawingpapereditor.cpp 22 | 23 | HEADERS += \ 24 | mainwindow.h \ 25 | views/drawingpapereditor/drawingpapereditor.h 26 | 27 | FORMS += 28 | 29 | # Default rules for deployment. 30 | qnx: target.path = /tmp/$${TARGET}/bin 31 | else: unix:!android: target.path = /opt/$${TARGET}/bin 32 | !isEmpty(target.path): INSTALLS += target 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QtDrawingPaperEditorDemo 2 | 3 | ## 零、效果图 4 | ![demo](https://github.com/robert1207/QtDrawingPaperEditorDemo/blob/master/doc/qt_drawing_paper_editor_img.gif) 5 | 6 | ## 一、原理说明: 7 | 实现在光标位置缩放画布的效果可以理解为,光标所对应到画布上的坐标点在缩放之前和之后都继续对应在光标所在的位置。而一般缩放画布,画布会以画布的左上角为固定点缩放,即画布大小变化后,左上角的位置不会发生变化。因此光标对应画布上的点在缩放后并不在原来的位置,而是发生了位移。因此把这个位移倒着移动回去,就实现了在光标位置点缩放画布的效果了。在任何系统平台上都可以按照这个原理实现在光标点缩放画布的效果。 8 | 9 | 验证“画布会以画布的左上角为固定点缩放”的方法: 10 | 在你实现了画布缩放之后,把鼠标光标移动到画布的左上角点上,然后滚动滑轮缩放,看画布是否是在鼠标点位置做放大缩小变化。如果是,那么说明你的缩放算法也是以画布左上角为原点缩放的。 11 | 12 | ## 二、算法实现: 13 | 这个算法的计算方法在各个平台重新按照这个计算步骤计算都可以实现光标点缩放画布的效果。 14 | 注:这里的实现为缩放参照点为左上角的点,比如放大,则会使矩形向右和向下放心延伸实现放大。 15 | 16 | ![chart1](https://github.com/robert1207/QtDrawingPaperEditorDemo/blob/master/doc/chart1.png) 17 | ![chart2](https://github.com/robert1207/QtDrawingPaperEditorDemo/blob/master/doc/chart2.png) 18 | 19 | a.计算原理: 20 | 1. 找到光标所对应到画布坐标系统的位置点,记为p0 21 | 2. 缩放 22 | 3. 找到缩放后步骤1中光标所对应画布点的新位置坐标点,记为p1 23 | 4. 计算p1点到p0点的位移量,包括x方向位移量move_len_x 和y方向位移量move_len_y 24 | 5. 把计算好的位移量应用到画布的位置移动上,从而实现缩放后画布上的点p1移动回去到p0,实现了光标位置缩放画布。 25 | 26 | 27 | b.计算步骤: 28 | 1. 获取p0 29 | 因为p0是值在画布中的坐标,而鼠标所在的坐标为窗口的坐标,分别为两个独立的坐标系,因此要根据鼠标在显示窗口的坐标计算出对应到画布坐标系上所对应的坐标 30 | p0.x = p3.x - p2.x 31 | p0.y = p3.y - p2.y 32 | 即 33 | p0(x, y) = (p3.x - p2.x, p3.y - p2.y) 34 | 35 | 2. 缩放的算法请参考源代码,原理是把画布的长宽按照比例放大或缩小并重新绘制 36 | 37 | 3. 计算p1点坐标,在图1所示可知: 38 | L0 = p0.x 39 | L2 = p0.y 40 | L1 = L0 * 缩放比例 41 | L3 = L2 * 缩放比例 42 | p1(x, y) = (L1, L3); 43 | 44 | 4. 计算位移量 45 | move_len_x = p1.x - p0.x; 46 | move_len_y = p1.y - p0.y; 47 | 48 | 5. 移动画布 49 | p2.x = p2.x - move_len_x; 50 | p2.y = p2.y - move_len_y; 51 | 52 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent) 7 | { 8 | setupUi(this); 9 | 10 | QVBoxLayout *centralLayout; 11 | centralLayout = new QVBoxLayout(centralwidget);//this layout represent the layout of "centralwidget" 12 | centralLayout->setObjectName(QString::fromUtf8("centralLayout")); 13 | 14 | QtDrawingPaperEditor *drawing_paper_editor; 15 | drawing_paper_editor = new QtDrawingPaperEditor(centralwidget); 16 | drawing_paper_editor->setObjectName(QString::fromUtf8("drawing_paper_editor")); 17 | centralLayout->addWidget(drawing_paper_editor); 18 | } 19 | 20 | MainWindow::~MainWindow() 21 | { 22 | 23 | } 24 | 25 | void MainWindow::setupUi(QMainWindow *MainWindow) 26 | { 27 | if (MainWindow->objectName().isEmpty()) 28 | MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 29 | MainWindow->resize(800, 600); 30 | centralwidget = new QWidget(MainWindow); 31 | centralwidget->setObjectName(QString::fromUtf8("centralwidget")); 32 | MainWindow->setCentralWidget(centralwidget); 33 | 34 | //MENU 35 | menubar = new QMenuBar(MainWindow); 36 | menubar->setObjectName(QString::fromUtf8("menubar")); 37 | MainWindow->setMenuBar(menubar); 38 | //STATUS 39 | statusbar = new QStatusBar(MainWindow); 40 | statusbar->setObjectName(QString::fromUtf8("statusbar")); 41 | MainWindow->setStatusBar(statusbar); 42 | 43 | retranslateUi(MainWindow); 44 | 45 | QMetaObject::connectSlotsByName(MainWindow); 46 | } // setupUi 47 | 48 | void MainWindow::retranslateUi(QMainWindow *MainWindow) 49 | { 50 | MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr)); 51 | } // retranslateUi 52 | 53 | -------------------------------------------------------------------------------- /views/drawingpapereditor/drawingpapereditor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Name QtDrawingPaperEditor 3 | * @Author Robert Zhang 4 | * @E-mail zhangzhiguo1207@163.com 5 | * @Date 2019-09-17 6 | */ 7 | 8 | #ifndef QTDRAWINGPAPEREDITOR_H 9 | #define QTDRAWINGPAPEREDITOR_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | class QtDrawingPaperEditor : public QWidget 18 | { 19 | Q_OBJECT 20 | public: 21 | explicit QtDrawingPaperEditor(QWidget *parent); 22 | ~QtDrawingPaperEditor() override; 23 | 24 | 25 | protected: 26 | void paintEvent(QPaintEvent *event) override; 27 | void mousePressEvent(QMouseEvent *event) override; 28 | void mouseMoveEvent(QMouseEvent *event) override; 29 | void mouseReleaseEvent(QMouseEvent *event) override; 30 | void resizeEvent(QResizeEvent *event) override; 31 | void enterEvent(QEvent *event) override; 32 | void leaveEvent(QEvent *event) override; 33 | void wheelEvent(QWheelEvent *event) override; 34 | 35 | private: 36 | double CalcPaperWidthOfPerPixel(double scale_value, 37 | int paper_width, 38 | int widget_width); 39 | void UpdatePaperWidthOfPerPixel(); 40 | void DrawPaper(QPainter &painter); 41 | 42 | int PaperWidth2DrawWidth(int paper_width); 43 | int DrawWidth2PaperWidth(int draw_width); 44 | void OnWheelValueChanged(QPoint mouse_pos, QPoint step); 45 | 46 | QPoint MousePoint2PaperPoint(QPoint point); 47 | void CentenThePaper(); 48 | 49 | 50 | private: 51 | QColor editor_bg_color_; 52 | QColor editor_paper_bg_color_; 53 | 54 | int paper_x_; 55 | int paper_y_; 56 | int paper_width_; 57 | int paper_height_; 58 | 59 | 60 | double scale_value_; 61 | double paper_width_of_per_pixel_; 62 | 63 | bool is_mouse_left_btn_down_; 64 | bool is_mouse_right_btn_down_; 65 | 66 | QPoint mouse_down_pos_; 67 | int orgin_dif_x_; 68 | int orgin_dif_y_; 69 | 70 | const double SCALE_VALUE_MAX = 20.0; 71 | const double SCALE_VALUE_MIN = 0.5; 72 | 73 | QRect draw_paper_rect_; 74 | 75 | }; 76 | 77 | #endif // QTDRAWINGPAPEREDITOR_H 78 | -------------------------------------------------------------------------------- /views/drawingpapereditor/drawingpapereditor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Name QtDrawingPaperEditor 3 | * @Author Robert Zhang 4 | * @E-mail zhangzhiguo1207@163.com 5 | * @Date 2019-09-17 6 | */ 7 | 8 | #include "drawingpapereditor.h" 9 | #include 10 | 11 | 12 | QtDrawingPaperEditor::QtDrawingPaperEditor(QWidget *parent) 13 | : QWidget(parent) 14 | { 15 | 16 | editor_bg_color_ = QColor(54, 54, 54); 17 | editor_paper_bg_color_ = QColor(27, 27, 27); 18 | 19 | paper_x_ = 0; 20 | paper_y_ = 0; 21 | paper_width_ = 1000; 22 | paper_height_ = 1000; 23 | 24 | scale_value_ = 0.9; 25 | 26 | is_mouse_left_btn_down_ = false; 27 | is_mouse_right_btn_down_ = false; 28 | 29 | 30 | UpdatePaperWidthOfPerPixel(); 31 | 32 | 33 | } 34 | 35 | QtDrawingPaperEditor::~QtDrawingPaperEditor() 36 | { 37 | 38 | } 39 | 40 | void QtDrawingPaperEditor::paintEvent(QPaintEvent *event) { 41 | 42 | Q_UNUSED(event) 43 | QPainter painter(this); 44 | 45 | //draw bg 46 | QRect frame_rect = this->rect(); 47 | painter.fillRect(frame_rect, QBrush(editor_bg_color_)); 48 | 49 | DrawPaper(painter); 50 | 51 | } 52 | 53 | void QtDrawingPaperEditor::mousePressEvent(QMouseEvent *event) { 54 | Q_UNUSED(event) 55 | if(event->buttons() & Qt::LeftButton) { 56 | 57 | is_mouse_left_btn_down_ = true; 58 | 59 | } else if(event->buttons() & Qt::RightButton) { 60 | mouse_down_pos_ = event->pos(); 61 | 62 | orgin_dif_x_ = mouse_down_pos_.x() - paper_x_; 63 | orgin_dif_y_ = mouse_down_pos_.y() - paper_y_; 64 | 65 | is_mouse_right_btn_down_ = true; 66 | 67 | } 68 | } 69 | 70 | void QtDrawingPaperEditor::mouseMoveEvent(QMouseEvent *event) { 71 | Q_UNUSED(event) 72 | if(is_mouse_right_btn_down_ == true) { 73 | 74 | paper_x_ = event->pos().x() - orgin_dif_x_; 75 | paper_y_ = event->pos().y() - orgin_dif_y_; 76 | update(); 77 | } 78 | } 79 | 80 | void QtDrawingPaperEditor::mouseReleaseEvent(QMouseEvent *event) { 81 | Q_UNUSED(event) 82 | 83 | is_mouse_left_btn_down_ = false; 84 | is_mouse_right_btn_down_ = false; 85 | } 86 | 87 | void QtDrawingPaperEditor::resizeEvent(QResizeEvent *event) { 88 | Q_UNUSED(event) 89 | UpdatePaperWidthOfPerPixel(); 90 | 91 | CentenThePaper(); 92 | } 93 | 94 | void QtDrawingPaperEditor::enterEvent(QEvent *event) { 95 | Q_UNUSED(event) 96 | } 97 | 98 | void QtDrawingPaperEditor::leaveEvent(QEvent *event) { 99 | Q_UNUSED(event) 100 | } 101 | 102 | void QtDrawingPaperEditor::wheelEvent(QWheelEvent *event) { 103 | Q_UNUSED(event) 104 | 105 | QPoint numPixels = event->pixelDelta(); 106 | QPoint numDegrees = event->angleDelta() / 8; 107 | 108 | if (!numPixels.isNull()) { 109 | OnWheelValueChanged(event->pos(),numPixels); 110 | } else if (!numDegrees.isNull()) { 111 | QPoint numSteps = numDegrees / 15; 112 | OnWheelValueChanged(event->pos(), numSteps); 113 | } 114 | event->accept(); 115 | } 116 | 117 | //scale_value : 0.5~ 20 118 | //paper_width : 119 | //widget_width : 120 | double QtDrawingPaperEditor::CalcPaperWidthOfPerPixel(double scale_value, 121 | int paper_width, 122 | int widget_width) { 123 | int paper_width_of_final_show = 124 | paper_width ;//+ static_cast(static_cast(paper_width )* 0.2); 125 | int scaled_widget_width = qRound(static_cast(widget_width) * scale_value); 126 | 127 | double paper_width_of_per_pixel = 128 | static_cast(paper_width_of_final_show) / 129 | static_cast(scaled_widget_width); 130 | 131 | //limit readable per-pixel value 132 | if(paper_width_of_per_pixel < 0.0005) paper_width_of_per_pixel = 0.0005; 133 | return paper_width_of_per_pixel; 134 | } 135 | 136 | //re-calc "paper_width_of_per_pixel" only when : init, resize, scale_value changed 137 | void QtDrawingPaperEditor::UpdatePaperWidthOfPerPixel() { 138 | if(this->height() >= this->width()) { 139 | paper_width_of_per_pixel_ = CalcPaperWidthOfPerPixel(scale_value_, paper_width_, this->width()); 140 | } else { 141 | paper_width_of_per_pixel_ = CalcPaperWidthOfPerPixel(scale_value_, paper_width_, this->height()); 142 | } 143 | } 144 | 145 | int QtDrawingPaperEditor::PaperWidth2DrawWidth(int paper_width) { 146 | double draw_width = static_cast(paper_width) / paper_width_of_per_pixel_; 147 | return qRound(draw_width); 148 | } 149 | 150 | int QtDrawingPaperEditor::DrawWidth2PaperWidth(int draw_width) { 151 | double paper_width = static_cast(draw_width) * paper_width_of_per_pixel_; 152 | return static_cast(qRound(paper_width)); 153 | } 154 | 155 | void QtDrawingPaperEditor::OnWheelValueChanged(QPoint mouse_pos, QPoint step) { 156 | 157 | //if mouse point in paper 158 | if(draw_paper_rect_.contains(mouse_pos)) { 159 | QPoint before_resize_mouse_point_at_paper = MousePoint2PaperPoint(mouse_pos); 160 | int temp_paper_point_x = DrawWidth2PaperWidth(before_resize_mouse_point_at_paper.x()); 161 | int temp_paper_point_y = DrawWidth2PaperWidth(before_resize_mouse_point_at_paper.y()); 162 | 163 | //resize 164 | int step_value = step.y(); 165 | scale_value_ += static_cast(step_value) /20.0; 166 | if(scale_value_ > SCALE_VALUE_MAX) scale_value_ = SCALE_VALUE_MAX; 167 | if(scale_value_ < SCALE_VALUE_MIN) scale_value_ = SCALE_VALUE_MIN; 168 | UpdatePaperWidthOfPerPixel(); 169 | 170 | int temp_draw_point_x = PaperWidth2DrawWidth(temp_paper_point_x); 171 | int temp_draw_point_y = PaperWidth2DrawWidth(temp_paper_point_y); 172 | QPoint after_resize_mouse_point_at_paper(temp_draw_point_x, temp_draw_point_y); 173 | 174 | 175 | QPoint should_move_length = after_resize_mouse_point_at_paper - before_resize_mouse_point_at_paper; 176 | 177 | paper_x_ -= should_move_length.x(); 178 | paper_y_ -= should_move_length.y(); 179 | 180 | update(); 181 | 182 | } else { //else using center resize 183 | int old_width = draw_paper_rect_.width(); 184 | int old_height = draw_paper_rect_.height(); 185 | 186 | //resize 187 | int step_value = step.y(); 188 | scale_value_ += static_cast(step_value) /20.0; 189 | if(scale_value_ > SCALE_VALUE_MAX) scale_value_ = SCALE_VALUE_MAX; 190 | if(scale_value_ < SCALE_VALUE_MIN) scale_value_ = SCALE_VALUE_MIN; 191 | UpdatePaperWidthOfPerPixel(); 192 | 193 | int new_width = PaperWidth2DrawWidth(paper_width_); 194 | int new_height = PaperWidth2DrawWidth(paper_height_); 195 | 196 | int adjusted_height = new_height - old_height; 197 | int adjusted_width = new_width - old_width; 198 | 199 | paper_x_ -= adjusted_width/2; 200 | paper_y_ -= adjusted_height/2; 201 | 202 | update(); 203 | } 204 | } 205 | 206 | void QtDrawingPaperEditor::DrawPaper(QPainter &painter) { 207 | 208 | int draw_width = PaperWidth2DrawWidth(paper_width_); 209 | int draw_height = PaperWidth2DrawWidth(paper_height_); 210 | 211 | draw_paper_rect_.setX(paper_x_); 212 | draw_paper_rect_.setY(paper_y_); 213 | draw_paper_rect_.setWidth(draw_width); 214 | draw_paper_rect_.setHeight(draw_height); 215 | painter.fillRect(draw_paper_rect_, QBrush(editor_paper_bg_color_)); 216 | 217 | /* 218 | QPixmap pixmap(":/img/image/jiji.png"); 219 | painter.drawPixmap(draw_paper_rect_, pixmap); 220 | */ 221 | 222 | double step_width = static_cast(draw_width) / 100.0; 223 | 224 | painter.setPen(QPen(Qt::white)); 225 | 226 | int start_x = paper_x_ + qRound(step_width/2); 227 | int start_y = paper_y_ + qRound(step_width/2); 228 | 229 | for(int y = 0; y < 100; y ++) { 230 | for(int x = 0; x < 100; x++) { 231 | int draw_point_x = start_x + qRound(x * step_width); 232 | int draw_point_y = start_y + qRound(y * step_width); 233 | painter.drawPoint(draw_point_x, draw_point_y); 234 | } 235 | } 236 | 237 | } 238 | 239 | QPoint QtDrawingPaperEditor::MousePoint2PaperPoint(QPoint point) { 240 | QPoint ret; 241 | ret.setX(point.x() - paper_x_); 242 | ret.setY(point.y() - paper_y_); 243 | return ret; 244 | } 245 | 246 | void QtDrawingPaperEditor::CentenThePaper() { 247 | 248 | scale_value_ = 0.9; 249 | UpdatePaperWidthOfPerPixel(); 250 | int adjust_distance_x = (this->width() - PaperWidth2DrawWidth(paper_width_)) / 2; 251 | int adjust_distance_y = (this->height() - PaperWidth2DrawWidth(paper_height_)) / 2; 252 | 253 | paper_x_ = adjust_distance_x; 254 | paper_y_ = adjust_distance_y; 255 | update(); 256 | } 257 | 258 | 259 | --------------------------------------------------------------------------------