Changeset View
Changeset View
Standalone View
Standalone View
src/part/simpleprintpreviewwindow_p.cpp
Show All 20 Lines | 19 | /* This file was part of the KDE project | |||
---|---|---|---|---|---|
21 | 21 | | |||
22 | This program is free software; you can redistribute it and/or | 22 | This program is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU Library General Public | 23 | modify it under the terms of the GNU Library General Public | ||
24 | License as published by the Free Software Foundation; either | 24 | License as published by the Free Software Foundation; either | ||
25 | version 2 of the License, or (at your option) any later version. | 25 | version 2 of the License, or (at your option) any later version. | ||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | #include "simpleprintpreviewwindow_p.h" | 28 | #include "simpleprintpreviewwindow_p.h" | ||
29 | #include "kgraphviewerlib_debug.h" | ||||
29 | #include "simpleprintingengine.h" | 30 | #include "simpleprintingengine.h" | ||
30 | #include "simpleprintingsettings.h" | 31 | #include "simpleprintingsettings.h" | ||
31 | #include "kgraphviewerlib_debug.h" | | |||
32 | 32 | | |||
33 | #include <QApplication> | ||||
33 | #include <QDebug> | 34 | #include <QDebug> | ||
35 | #include <QPaintEvent> | ||||
34 | #include <QPixmap> | 36 | #include <QPixmap> | ||
35 | #include <QResizeEvent> | 37 | #include <QResizeEvent> | ||
36 | #include <QPaintEvent> | | |||
37 | #include <QStyle> | 38 | #include <QStyle> | ||
38 | #include <QApplication> | | |||
39 | 39 | | |||
40 | namespace KGraphViewer | 40 | namespace KGraphViewer | ||
41 | { | 41 | { | ||
42 | 42 | KGVSimplePrintPreviewView::KGVSimplePrintPreviewView(KGVSimplePrintPreviewWindow *window) | |||
43 | KGVSimplePrintPreviewView::KGVSimplePrintPreviewView( | 43 | : QWidget() | ||
44 | KGVSimplePrintPreviewWindow *window) | 44 | , m_window(window) | ||
45 | : QWidget(), | | |||
46 | m_window(window) | | |||
47 | { | 45 | { | ||
48 | qCDebug(KGRAPHVIEWERLIB_LOG) << "KGVSimplePrintPreviewView"; | 46 | qCDebug(KGRAPHVIEWERLIB_LOG) << "KGVSimplePrintPreviewView"; | ||
49 | /* resize(300,400); | 47 | /* resize(300,400); | ||
50 | resizeContents(200, 400);*/ | 48 | resizeContents(200, 400);*/ | ||
51 | //setAttribute(Qt::WA_PaintOutsidePaintEvent,true); | 49 | // setAttribute(Qt::WA_PaintOutsidePaintEvent,true); | ||
52 | } | 50 | } | ||
53 | 51 | | |||
54 | void KGVSimplePrintPreviewView::paintEvent( QPaintEvent *pe ) | 52 | void KGVSimplePrintPreviewView::paintEvent(QPaintEvent *pe) | ||
55 | { | 53 | { | ||
56 | qCDebug(KGRAPHVIEWERLIB_LOG) << pe; | 54 | qCDebug(KGRAPHVIEWERLIB_LOG) << pe; | ||
57 | Q_UNUSED(pe); | 55 | Q_UNUSED(pe); | ||
58 | 56 | | |||
59 | QPainter p(this); | 57 | QPainter p(this); | ||
60 | // QPainter p(m_window); | 58 | // QPainter p(m_window); | ||
61 | // p.begin(&pm); | 59 | // p.begin(&pm); | ||
62 | // p.initFrom(this); | 60 | // p.initFrom(this); | ||
63 | //! @todo only for screen! | 61 | //! @todo only for screen! | ||
64 | qCDebug(KGRAPHVIEWERLIB_LOG) << "filling rect"; | 62 | qCDebug(KGRAPHVIEWERLIB_LOG) << "filling rect"; | ||
65 | p.fillRect(QRect(QPoint(0,0),m_window->size()), QBrush(Qt::white));//pe->rect(), QBrush(white)); | 63 | p.fillRect(QRect(QPoint(0, 0), m_window->size()), QBrush(Qt::white)); // pe->rect(), QBrush(white)); | ||
66 | if (m_window->currentPage()>=0) | 64 | if (m_window->currentPage() >= 0) { | ||
67 | { | | |||
68 | qCDebug(KGRAPHVIEWERLIB_LOG) << "painting page"; | 65 | qCDebug(KGRAPHVIEWERLIB_LOG) << "painting page"; | ||
69 | m_window->m_engine.paintPage(m_window->currentPage(), p); | 66 | m_window->m_engine.paintPage(m_window->currentPage(), p); | ||
70 | } | 67 | } | ||
71 | // emit m_window->paintingPageRequested(m_window->currentPage(), p); | 68 | // emit m_window->paintingPageRequested(m_window->currentPage(), p); | ||
72 | p.end(); | 69 | p.end(); | ||
73 | } | 70 | } | ||
74 | 71 | | |||
75 | // TODO: redo usages instead with QStyle::PM_Layout{Top,Left,Right,Bottom}Margin | 72 | // TODO: redo usages instead with QStyle::PM_Layout{Top,Left,Right,Bottom}Margin | ||
76 | #define KGVSimplePrintPreviewScrollView_MARGIN QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) | 73 | #define KGVSimplePrintPreviewScrollView_MARGIN QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) | ||
77 | 74 | | |||
78 | KGVSimplePrintPreviewScrollView::KGVSimplePrintPreviewScrollView( | 75 | KGVSimplePrintPreviewScrollView::KGVSimplePrintPreviewScrollView(KGVSimplePrintPreviewWindow *window) | ||
79 | KGVSimplePrintPreviewWindow *window) : QScrollArea(window), m_window(window) | 76 | : QScrollArea(window) | ||
77 | , m_window(window) | ||||
80 | { | 78 | { | ||
81 | // this->settings = settings; | 79 | // this->settings = settings; | ||
82 | m_view = new KGVSimplePrintPreviewView(m_window); | 80 | m_view = new KGVSimplePrintPreviewView(m_window); | ||
83 | 81 | | |||
84 | /* int widthMM = KgvPageFormat::width( | 82 | /* int widthMM = KgvPageFormat::width( | ||
85 | settings.pageLayout.format, settings.pageLayout.orientation); | 83 | settings.pageLayout.format, settings.pageLayout.orientation); | ||
86 | int heightMM = KgvPageFormat::height( | 84 | int heightMM = KgvPageFormat::height( | ||
87 | settings.pageLayout.format, settings.pageLayout.orientation); | 85 | settings.pageLayout.format, settings.pageLayout.orientation); | ||
88 | // int constantHeight = 400; | 86 | // int constantHeight = 400; | ||
89 | // m_view->resize(constantHeight * widthMM / heightMM, constantHeight ); //keep aspect | 87 | // m_view->resize(constantHeight * widthMM / heightMM, constantHeight ); //keep aspect | ||
90 | */ | 88 | */ | ||
91 | setWidget(m_view); | 89 | setWidget(m_view); | ||
92 | } | 90 | } | ||
93 | 91 | | |||
94 | void KGVSimplePrintPreviewScrollView::paintEvent( QPaintEvent *pe ) | 92 | void KGVSimplePrintPreviewScrollView::paintEvent(QPaintEvent *pe) | ||
95 | { | 93 | { | ||
96 | qCDebug(KGRAPHVIEWERLIB_LOG) << widget(); | 94 | qCDebug(KGRAPHVIEWERLIB_LOG) << widget(); | ||
97 | QScrollArea::paintEvent(pe); | 95 | QScrollArea::paintEvent(pe); | ||
98 | ((KGVSimplePrintPreviewView*)widget())->paintEvent(pe); | 96 | ((KGVSimplePrintPreviewView *)widget())->paintEvent(pe); | ||
99 | } | 97 | } | ||
100 | 98 | | |||
101 | // void KGVSimplePrintPreviewScrollView::resizeEvent( QResizeEvent *re ) | 99 | // void KGVSimplePrintPreviewScrollView::resizeEvent( QResizeEvent *re ) | ||
102 | // { | 100 | // { | ||
103 | // QScrollArea::resizeEvent(re); | 101 | // QScrollArea::resizeEvent(re); | ||
104 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << re->size().width() << " " << re->size().height(); | 102 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << re->size().width() << " " << re->size().height(); | ||
105 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << contentsWidth() << " " << contentsHeight(); | 103 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << contentsWidth() << " " << contentsHeight(); | ||
106 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << m_view->width() << " " << m_view->height(); | 104 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << m_view->width() << " " << m_view->height(); | ||
Show All 10 Lines | |||||
117 | // (contentsHeight() - m_view->height())/2); | 115 | // (contentsHeight() - m_view->height())/2); | ||
118 | // } | 116 | // } | ||
119 | // setUpdatesEnabled(true); | 117 | // setUpdatesEnabled(true); | ||
120 | // } | 118 | // } | ||
121 | 119 | | |||
122 | void KGVSimplePrintPreviewScrollView::setFullWidth() | 120 | void KGVSimplePrintPreviewScrollView::setFullWidth() | ||
123 | { | 121 | { | ||
124 | viewport()->setUpdatesEnabled(false); | 122 | viewport()->setUpdatesEnabled(false); | ||
125 | double widthMM = KgvPageFormat::width( | 123 | double widthMM = KgvPageFormat::width(m_window->settings()->pageLayout.format, m_window->settings()->pageLayout.orientation); | ||
126 | m_window->settings()->pageLayout.format, | 124 | double heightMM = KgvPageFormat::height(m_window->settings()->pageLayout.format, m_window->settings()->pageLayout.orientation); | ||
127 | m_window->settings()->pageLayout.orientation); | | |||
128 | double heightMM = KgvPageFormat::height( | | |||
129 | m_window->settings()->pageLayout.format, m_window->settings()->pageLayout.orientation); | | |||
130 | // int constantWidth = m_window->width()- KGVSimplePrintPreviewScrollView_MARGIN*6; | 125 | // int constantWidth = m_window->width()- KGVSimplePrintPreviewScrollView_MARGIN*6; | ||
131 | double constantWidth = width() - KGVSimplePrintPreviewScrollView_MARGIN*6; | 126 | double constantWidth = width() - KGVSimplePrintPreviewScrollView_MARGIN * 6; | ||
132 | double heightForWidth = constantWidth * heightMM / widthMM; | 127 | double heightForWidth = constantWidth * heightMM / widthMM; | ||
133 | // heightForWidth = qMin(kapp->desktop()->height()*4/5, heightForWidth); | 128 | // heightForWidth = qMin(kapp->desktop()->height()*4/5, heightForWidth); | ||
134 | constantWidth = heightForWidth * widthMM / heightMM; | 129 | constantWidth = heightForWidth * widthMM / heightMM; | ||
135 | m_view->resize((int)constantWidth, (int)heightForWidth); //keep aspect | 130 | m_view->resize((int)constantWidth, (int)heightForWidth); // keep aspect | ||
136 | /* resizeContents(int(m_view->width() + 2*KGVSimplePrintPreviewScrollView_MARGIN), | 131 | /* resizeContents(int(m_view->width() + 2*KGVSimplePrintPreviewScrollView_MARGIN), | ||
137 | int(m_view->height() + 2*KGVSimplePrintPreviewScrollView_MARGIN));*/ | 132 | int(m_view->height() + 2*KGVSimplePrintPreviewScrollView_MARGIN));*/ | ||
138 | /* moveChild(m_view, (contentsWidth()-m_view->width())/2, | 133 | /* moveChild(m_view, (contentsWidth()-m_view->width())/2, | ||
139 | (contentsHeight()-m_view->height())/2);*/ | 134 | (contentsHeight()-m_view->height())/2);*/ | ||
140 | viewport()->setUpdatesEnabled(true); | 135 | viewport()->setUpdatesEnabled(true); | ||
141 | resize(size()+QSize(1,1)); //to update pos. | 136 | resize(size() + QSize(1, 1)); // to update pos. | ||
142 | // m_view->enablePainting = true; | 137 | // m_view->enablePainting = true; | ||
143 | m_view->repaint(); | 138 | m_view->repaint(); | ||
144 | } | 139 | } | ||
145 | 140 | | |||
146 | // void KGVSimplePrintPreviewScrollView::setContentsPos(int x, int y) | 141 | // void KGVSimplePrintPreviewScrollView::setContentsPos(int x, int y) | ||
147 | // { | 142 | // { | ||
148 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << "############" << x << " " << y << " " << contentsX()<< " " <<contentsY(); | 143 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << "############" << x << " " << y << " " << contentsX()<< " " <<contentsY(); | ||
149 | // if (x<0 || y<0) //to avoid endless loop on Linux | 144 | // if (x<0 || y<0) //to avoid endless loop on Linux | ||
150 | // return; | 145 | // return; | ||
151 | // QScrollArea::setContentsPos(x,y); | 146 | // QScrollArea::setContentsPos(x,y); | ||
152 | // } | 147 | // } | ||
153 | 148 | | |||
154 | } | 149 | } |