Thank you, your solution help me very much. In fact, I used a a QGraphicsItems based canvas. But now I know another approach. Thank a lot :)
On Wed, Mar 16, 2011 at 2:13 PM, Boudewijn Rempt <b...@valdyas.org> wrote: > On Friday 11 March 2011 Mar, tien dh wrote: > > Hi every one, > > Please help me on that problem, it's so difficult for me to solve: > > > > int main(int argc, char** argv){ QApplication qapp(argc, argv); > > KComponentData cd("graphicsview-test"); Calligra::Tables::Doc doc; > > bool ok = > doc.*openUrl*(KUrl("/home/excel_samples/Cash_Flow_Projection_Worksheet.xls")); > > if (!ok) { qDebug() << "failed to load"; return 0; > > } QFont font(KoGlobal::defaultFont()); > > Calligra::Tables::CanvasItem* canvas = new > > Calligra::Tables::CanvasItem(&doc); QRect usedArea = > > canvas->*activeSheet*()->usedArea(true); QSizeF > > size(canvas->*activeSheet*()->columnPosition(usedArea.right()+3), > > canvas->*activeSheet*()->rowPosition(usedArea.bottom()+5)); > > canvas->setDocumentSize(size); size = > > canvas->*zoomHandler*()->*documentToView*(size); > > canvas->resize(size); canvas->setPos(0, 0); > > Calligra::Tables::ColumnHeaderItem* columnHeader = > > > static_cast<Calligra::Tables::ColumnHeaderItem*>(canvas->*columnHeader*()); > > static_cast<QGraphicsWidget*>(columnHeader)->resize(size.width(), > > canvas->*zoomHandler*()->zoomItY(font.pointSizeF() + 3)); > > columnHeader->setPos(0, -columnHeader->height()); > > Calligra::Tables::RowHeaderItem* rowHeader = > > static_cast<Calligra::Tables::RowHeaderItem*>(canvas->*rowHeader*()); > > > static_cast<QGraphicsWidget*>(rowHeader)->resize(canvas->*zoomHandler*()->zoomItX(YBORDER_WIDTH), > > size.height()); rowHeader->setPos(-rowHeader->width(), 0); > > columnHeader->toolChanged("PanTool"); > > rowHeader->toolChanged("PanTool"); QGraphicsScene scene; > > scene.addItem(canvas); scene.addItem(columnHeader); > > scene.addItem(rowHeader); QGraphicsView view(&scene); > > view.show(); qapp.exec();} > > > > > > This portion of code can run and show a excel file. But when I try using > > function: doc.createView().show, only tabbars and scrollbars shown. Sheet > > area is completely black. I try using canvas, canvasWidget and > > canvasController but it isn't successful. > > Anyone can show me why it is and how to render the view to an image ? > > Hi Tien, > > I'm not completely sure what you're tring to do here -- the mail came > across a bit garbled. It looks like you're using the graphicsitem canvas, > and in that case, you shouldn't use the createView() method since that > creates a view. But what might be happening here is that your implementation > of KoCanvasController doesn't size your canvas correctly. This is a bit > fiddly, and we don't have any good example yet of how it should work. I'm > working on that, but I haven't had a whole lot of time yet, plus, the code > is still in a state of flux. You need to make sure, though, that your > KoCanvasController implementation is complete -- this is the viewport that > handles the display of the correct part of the document -- and that you set > the canvas on that. > > And make sure that you either use the QWidget based canvas or the > QGraphicsItem based canvas. If you use the QWidget-based canvas, use the > KoAbstraction library. This is by far the simplest solution, since it only > implies implementing two abstract classes. > > Here's some sample code written by Mani Chandrasekar for his > conf.kde.inpresentation that shows how it works: > > you need to implement two classes (this is the absolute minimum): > > ------------- > > KoAbstractApplicationWindow > KoAbstractApplicationController > > > MainWindow::MainWindow(QWidget *parent) : > QMainWindow(parent), > KoAbstractApplicationWindow((m_controller > = new MyApplicationController(this))), > ui(new Ui::MainWindow) > { > ui->setupUi(this); > > } > > MainWindow::~MainWindow() > { > delete ui; > } > > ---------------- > > MyApplicationController::MyApplicationController(MainWindow *window) > : KoAbstractApplicationController(window), > m_window(window) > { > } > > QWidget * MyApplicationController::mainWindow() const > { > return m_window; > } > > void MyApplicationController::setCentralWidget(QWidget *widget) > { > m_window->setCentralWidget(widget); > } > > > -------------------- > > And then it's simply a matter of instantiating and calling the method to > open a file: > > int main(int argc, char *argv[]) > { > QApplication a(argc, argv); > > MainWindow wnd; > wnd.show(); > > > wnd.controller()->openDocument("/home/mani/Downloads/MicromaxMMX300G.ppt"); > return a.exec(); > } > > -- > Boudewijn Rempt | http://www.valdyas.org, http://www.krita.org > _______________________________________________ > calligra-devel mailing list > calligra-devel@kde.org > https://mail.kde.org/mailman/listinfo/calligra-devel > -- Do Huu Tien Handphone No: 0972471786 Email: tiendh11...@gmail.com Y!M: dohuu_tien86
_______________________________________________ calligra-devel mailing list calligra-devel@kde.org https://mail.kde.org/mailman/listinfo/calligra-devel