File indexing completed on 2024-05-12 16:35:55
0001 /* This file is part of the KDE project 0002 Copyright 2010 - Marijn Kruisselbrink <mkruisselbrink@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 #include <QApplication> 0020 #include <QGraphicsView> 0021 #include <QGraphicsScene> 0022 #include <QDebug> 0023 0024 #include <KoGlobal.h> 0025 #include <KoZoomHandler.h> 0026 0027 #include <part/Doc.h> 0028 #include <part/Part.h> 0029 #include <part/CanvasItem.h> 0030 #include <part/HeaderItems.h> 0031 #include <Sheet.h> 0032 0033 int main(int argc, char** argv) 0034 { 0035 QApplication qapp(argc, argv); 0036 0037 Calligra::Sheets::Part part; 0038 Calligra::Sheets::Doc doc(&part); 0039 part.setDocument(&doc); 0040 0041 0042 bool ok = doc.openUrl(QUrl("/home/marijn/kde/src/calligra/docs/oos_AMSAT-IARU_Link_Model.ods")); 0043 if (!ok) { 0044 qDebug() << "failed to load"; 0045 return 0; 0046 } 0047 0048 QFont font(KoGlobal::defaultFont()); 0049 0050 Calligra::Sheets::CanvasItem* canvas = new Calligra::Sheets::CanvasItem(&doc); 0051 0052 QRect usedArea = canvas->activeSheet()->usedArea(true); 0053 QFontMetricsF fm(font, 0); 0054 QSizeF size(canvas->activeSheet()->columnPosition(usedArea.right()+3), canvas->activeSheet()->rowPosition(usedArea.bottom()+5)); 0055 canvas->setDocumentSize(size); 0056 size = canvas->zoomHandler()->documentToView(size); 0057 canvas->resize(size); 0058 canvas->setPos(0, 0); 0059 0060 Calligra::Sheets::ColumnHeaderItem* columnHeader = static_cast<Calligra::Sheets::ColumnHeaderItem*>(canvas->columnHeader()); 0061 static_cast<QGraphicsWidget*>(columnHeader)->resize(size.width(), fm.height() + 3); 0062 columnHeader->setPos(0, -columnHeader->height()); 0063 0064 Calligra::Sheets::RowHeaderItem* rowHeader = static_cast<Calligra::Sheets::RowHeaderItem*>(canvas->rowHeader()); 0065 static_cast<QGraphicsWidget*>(rowHeader)->resize(fm.width(QString::fromLatin1("99999")) + 3, size.height()); 0066 rowHeader->setPos(-rowHeader->width(), 0); 0067 0068 columnHeader->toolChanged("PanTool"); 0069 rowHeader->toolChanged("PanTool"); 0070 0071 QGraphicsScene scene; 0072 scene.addItem(canvas); 0073 scene.addItem(columnHeader); 0074 scene.addItem(rowHeader); 0075 0076 QGraphicsView view(&scene); 0077 view.show(); 0078 0079 qapp.exec(); 0080 }