--===============1707383712== Content-Type: multipart/alternative; boundary=90e6ba53a5f0dd9b04049eb93b02 --90e6ba53a5f0dd9b04049eb93b02 Content-Type: text/plain; charset=ISO-8859-1 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 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(canvas->*columnHeader*()); > > static_cast(columnHeader)->resize(size.width(), > > canvas->*zoomHandler*()->zoomItY(font.pointSizeF() + 3)); > > columnHeader->setPos(0, -columnHeader->height()); > > Calligra::Tables::RowHeaderItem* rowHeader = > > static_cast(canvas->*rowHeader*()); > > > static_cast(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: tiendh11986@gmail.com Y!M: dohuu_tien86 --90e6ba53a5f0dd9b04049eb93b02 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank you, your solution help me very much. In fact, I used a a QGraphicsIt= ems based canvas. But now I know another approach. Thank a lot :)

On Wed, Mar 16, 2011 at 2:13 PM, Boudewijn Rempt <= span dir=3D"ltr"><boud@valdyas.org> wrote:
<= div class=3D"h5">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:=
>
> =A0int main(int argc, char** argv){ =A0 =A0QApplication qapp(argc, arg= v);
> KComponentData cd("graphicsview-test"); =A0 =A0Calligra::Tab= les::Doc doc;
> =A0 bool ok =3D doc.*openUrl*(KUrl("/home/excel_samples/Cash_Flow= _Projection_Worksheet.xls"));
> =A0 =A0if (!ok) { =A0 =A0 =A0 =A0qDebug() << "failed to loa= d"; =A0 =A0 =A0 =A0return 0;
> } =A0 =A0QFont font(KoGlobal::defaultFont());
> Calligra::Tables::CanvasItem* canvas =3D new
> Calligra::Tables::CanvasItem(&doc); =A0 =A0QRect usedArea =3D
> canvas->*activeSheet*()->usedArea(true); =A0 =A0QSizeF
> size(canvas->*activeSheet*()->columnPosition(usedArea.right()+3)= ,
> canvas->*activeSheet*()->rowPosition(usedArea.bottom()+5));
> canvas->setDocumentSize(size); =A0 =A0size =3D
> canvas->*zoomHandler*()->*documentToView*(size);
> canvas->resize(size); =A0 =A0canvas->setPos(0, 0);
> Calligra::Tables::ColumnHeaderItem* columnHeader =3D
> static_cast<Calligra::Tables::ColumnHeaderItem*>(canvas->*col= umnHeader*());
> =A0 =A0static_cast<QGraphicsWidget*>(columnHeader)->resize(si= ze.width(),
> canvas->*zoomHandler*()->zoomItY(font.pointSizeF() + 3));
> columnHeader->setPos(0, -columnHeader->height());
> Calligra::Tables::RowHeaderItem* rowHeader =3D
> static_cast<Calligra::Tables::RowHeaderItem*>(canvas->*rowHea= der*());
> =A0 static_cast<QGraphicsWidget*>(rowHeader)->resize(canvas-&= gt;*zoomHandler*()->zoomItX(YBORDER_WIDTH),
> size.height()); =A0 =A0rowHeader->setPos(-rowHeader->width(), 0)= ;
> columnHeader->toolChanged("PanTool");
> rowHeader->toolChanged("PanTool"); =A0 =A0 =A0 =A0QGraphi= csScene scene;
> scene.addItem(canvas); =A0 =A0scene.addItem(columnHeader);
> scene.addItem(rowHeader); =A0 =A0QGraphicsView view(&scene);
> view.show(); =A0 =A0qapp.exec();}
>
>
> This portion of code can run and show a excel file. But when I try usi= ng
> function: doc.createView().show, only tabbars and scrollbars shown. Sh= eet
> 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 ?<= br>
Hi Tien,

I'm not completely sure what you're tring to do here -- the mail ca= me across a bit garbled. It looks like you're using the graphicsitem ca= nvas, 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 impleme= ntation 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 shoul= d 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, tho= ugh, that your KoCanvasController implementation is complete -- this is the= viewport that handles the display of the correct part of the document -- a= nd that you set the canvas on that.

And make sure that you either use the QWidget based canvas or the QGraphics= Item based canvas. If you use the QWidget-based canvas, use the KoAbstracti= on library. This is by far the simplest solution, since it only implies imp= lementing two abstract classes.

Here's some sample code written by Mani Chandrasekar for his
conf.kde.in presentation that sh= ows how it works:

you need to implement two classes (this is the absolute minimum):

-------------

KoAbstractApplicationWindow
KoAbstractApplicationController


MainWindow::MainWindow(QWidget *parent) :
=A0 =A0QMainWindow(parent),
=A0 =A0KoAbstractApplicationWindow((m_controller
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D new My= ApplicationController(this))),
=A0 =A0ui(new Ui::MainWindow)
{
=A0 =A0ui->setupUi(this);

}

MainWindow::~MainWindow()
{
=A0 =A0delete ui;
}

----------------

MyApplicationController::MyApplicationController(MainWindow *window)
=A0 =A0: KoAbstractApplicationController(window),
=A0 =A0m_window(window)
{
}

QWidget * MyApplicationController::mainWindow() const
{
=A0 =A0return m_window;
}

void MyApplicationController::setCentralWidget(QWidget *widget)
{
=A0 =A0m_window->setCentralWidget(widget);
}


--------------------

And then it's simply a matter of instantiating and calling the method t= o open a file:

int main(int argc, char *argv[])
{
=A0 =A0QApplication a(argc, argv);

=A0 =A0MainWindow wnd;
=A0 =A0wnd.show();

=A0 =A0wnd.controller()->openDocument("/home/mani/Downloads/Microm= axMMX300G.ppt");
=A0 =A0return 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
H= andphone No: 0972471786
Email: = tiendh11986@gmail.com
Y!M: dohuu_tien86
--90e6ba53a5f0dd9b04049eb93b02-- --===============1707383712== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ calligra-devel mailing list calligra-devel@kde.org https://mail.kde.org/mailman/listinfo/calligra-devel --===============1707383712==--