File indexing completed on 2024-05-19 15:27:53
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 /* This file was part of the KDE project 0020 Copyright (C) 2005 Jarosław Staniek <staniek@kde.org> 0021 0022 This program is free software; you can redistribute it and/or 0023 modify it under the terms of the GNU Library General Public 0024 License as published by the Free Software Foundation; either 0025 version 2 of the License, or (at your option) any later version. 0026 */ 0027 0028 #include "simpleprintpreviewwindow_p.h" 0029 #include "kgraphviewerlib_debug.h" 0030 #include "simpleprintingengine.h" 0031 #include "simpleprintingsettings.h" 0032 0033 #include <QApplication> 0034 #include <QDebug> 0035 #include <QPaintEvent> 0036 #include <QPixmap> 0037 #include <QResizeEvent> 0038 #include <QStyle> 0039 0040 namespace KGraphViewer 0041 { 0042 KGVSimplePrintPreviewView::KGVSimplePrintPreviewView(KGVSimplePrintPreviewWindow *window) 0043 : QWidget() 0044 , m_window(window) 0045 { 0046 qCDebug(KGRAPHVIEWERLIB_LOG) << "KGVSimplePrintPreviewView"; 0047 /* resize(300,400); 0048 resizeContents(200, 400);*/ 0049 // setAttribute(Qt::WA_PaintOutsidePaintEvent,true); 0050 } 0051 0052 void KGVSimplePrintPreviewView::paintEvent(QPaintEvent *pe) 0053 { 0054 qCDebug(KGRAPHVIEWERLIB_LOG) << pe; 0055 Q_UNUSED(pe); 0056 0057 QPainter p(this); 0058 // QPainter p(m_window); 0059 // p.begin(&pm); 0060 // p.initFrom(this); 0061 //! @todo only for screen! 0062 qCDebug(KGRAPHVIEWERLIB_LOG) << "filling rect"; 0063 p.fillRect(QRect(QPoint(0, 0), m_window->size()), QBrush(Qt::white)); // pe->rect(), QBrush(white)); 0064 if (m_window->currentPage() >= 0) { 0065 qCDebug(KGRAPHVIEWERLIB_LOG) << "painting page"; 0066 m_window->m_engine.paintPage(m_window->currentPage(), p); 0067 } 0068 // emit m_window->paintingPageRequested(m_window->currentPage(), p); 0069 p.end(); 0070 } 0071 0072 // TODO: redo usages instead with QStyle::PM_Layout{Top,Left,Right,Bottom}Margin 0073 #define KGVSimplePrintPreviewScrollView_MARGIN QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) 0074 0075 KGVSimplePrintPreviewScrollView::KGVSimplePrintPreviewScrollView(KGVSimplePrintPreviewWindow *window) 0076 : QScrollArea(window) 0077 , m_window(window) 0078 { 0079 // this->settings = settings; 0080 m_view = new KGVSimplePrintPreviewView(m_window); 0081 0082 /* int widthMM = KgvPageFormat::width( 0083 settings.pageLayout.format, settings.pageLayout.orientation); 0084 int heightMM = KgvPageFormat::height( 0085 settings.pageLayout.format, settings.pageLayout.orientation); 0086 // int constantHeight = 400; 0087 // m_view->resize(constantHeight * widthMM / heightMM, constantHeight ); //keep aspect 0088 */ 0089 setWidget(m_view); 0090 } 0091 0092 void KGVSimplePrintPreviewScrollView::paintEvent(QPaintEvent *pe) 0093 { 0094 qCDebug(KGRAPHVIEWERLIB_LOG) << widget(); 0095 QScrollArea::paintEvent(pe); 0096 ((KGVSimplePrintPreviewView *)widget())->paintEvent(pe); 0097 } 0098 0099 // void KGVSimplePrintPreviewScrollView::resizeEvent( QResizeEvent *re ) 0100 // { 0101 // QScrollArea::resizeEvent(re); 0102 // // qCDebug(KGRAPHVIEWERLIB_LOG) << re->size().width() << " " << re->size().height(); 0103 // // qCDebug(KGRAPHVIEWERLIB_LOG) << contentsWidth() << " " << contentsHeight(); 0104 // // qCDebug(KGRAPHVIEWERLIB_LOG) << m_view->width() << " " << m_view->height(); 0105 // setUpdatesEnabled(false); 0106 // if (re->size().width() > (m_view->width()+2*KGVSimplePrintPreviewScrollView_MARGIN) 0107 // || re->size().height() > (m_view->height()+2*KGVSimplePrintPreviewScrollView_MARGIN)) 0108 // { 0109 // resizeContents( 0110 // qMax(re->size().width(), m_view->width()+2*KGVSimplePrintPreviewScrollView_MARGIN), 0111 // qMax(re->size().height(), m_view->height()+2*KGVSimplePrintPreviewScrollView_MARGIN)); 0112 // 0113 // int vscrbarWidth = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0; 0114 // moveChild(m_view, (contentsWidth() - vscrbarWidth - m_view->width())/2, 0115 // (contentsHeight() - m_view->height())/2); 0116 // } 0117 // setUpdatesEnabled(true); 0118 // } 0119 0120 void KGVSimplePrintPreviewScrollView::setFullWidth() 0121 { 0122 viewport()->setUpdatesEnabled(false); 0123 double widthMM = KgvPageFormat::width(m_window->settings()->pageLayout.format, m_window->settings()->pageLayout.orientation); 0124 double heightMM = KgvPageFormat::height(m_window->settings()->pageLayout.format, m_window->settings()->pageLayout.orientation); 0125 // int constantWidth = m_window->width()- KGVSimplePrintPreviewScrollView_MARGIN*6; 0126 double constantWidth = width() - KGVSimplePrintPreviewScrollView_MARGIN * 6; 0127 double heightForWidth = constantWidth * heightMM / widthMM; 0128 // heightForWidth = qMin(kapp->desktop()->height()*4/5, heightForWidth); 0129 constantWidth = heightForWidth * widthMM / heightMM; 0130 m_view->resize((int)constantWidth, (int)heightForWidth); // keep aspect 0131 /* resizeContents(int(m_view->width() + 2*KGVSimplePrintPreviewScrollView_MARGIN), 0132 int(m_view->height() + 2*KGVSimplePrintPreviewScrollView_MARGIN));*/ 0133 /* moveChild(m_view, (contentsWidth()-m_view->width())/2, 0134 (contentsHeight()-m_view->height())/2);*/ 0135 viewport()->setUpdatesEnabled(true); 0136 resize(size() + QSize(1, 1)); // to update pos. 0137 // m_view->enablePainting = true; 0138 m_view->repaint(); 0139 } 0140 0141 // void KGVSimplePrintPreviewScrollView::setContentsPos(int x, int y) 0142 // { 0143 // // qCDebug(KGRAPHVIEWERLIB_LOG) << "############" << x << " " << y << " " << contentsX()<< " " <<contentsY(); 0144 // if (x<0 || y<0) //to avoid endless loop on Linux 0145 // return; 0146 // QScrollArea::setContentsPos(x,y); 0147 // } 0148 0149 } 0150 0151 #include "moc_simpleprintpreviewwindow_p.cpp"