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 :)<br><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 2:13 PM, Boudewijn Rempt <span dir="ltr"><<a href="mailto:boud@valdyas.org">boud@valdyas.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">On Friday 11 March 2011 Mar, tien dh wrote:<br>
> Hi every one,<br>
> Please help me on that problem, it's so difficult for me to solve:<br>
><br>
>  int main(int argc, char** argv){    QApplication qapp(argc, argv);<br>
> KComponentData cd("graphicsview-test");    Calligra::Tables::Doc doc;<br>
>   bool ok = doc.*openUrl*(KUrl("/home/excel_samples/Cash_Flow_Projection_Worksheet.xls"));<br>
>    if (!ok) {        qDebug() << "failed to load";        return 0;<br>
> }    QFont font(KoGlobal::defaultFont());<br>
> Calligra::Tables::CanvasItem* canvas = new<br>
> Calligra::Tables::CanvasItem(&doc);    QRect usedArea =<br>
> canvas->*activeSheet*()->usedArea(true);    QSizeF<br>
> size(canvas->*activeSheet*()->columnPosition(usedArea.right()+3),<br>
> canvas->*activeSheet*()->rowPosition(usedArea.bottom()+5));<br>
> canvas->setDocumentSize(size);    size =<br>
> canvas->*zoomHandler*()->*documentToView*(size);<br>
> canvas->resize(size);    canvas->setPos(0, 0);<br>
> Calligra::Tables::ColumnHeaderItem* columnHeader =<br>
> static_cast<Calligra::Tables::ColumnHeaderItem*>(canvas->*columnHeader*());<br>
>    static_cast<QGraphicsWidget*>(columnHeader)->resize(size.width(),<br>
> canvas->*zoomHandler*()->zoomItY(font.pointSizeF() + 3));<br>
> columnHeader->setPos(0, -columnHeader->height());<br>
> Calligra::Tables::RowHeaderItem* rowHeader =<br>
> static_cast<Calligra::Tables::RowHeaderItem*>(canvas->*rowHeader*());<br>
>   static_cast<QGraphicsWidget*>(rowHeader)->resize(canvas->*zoomHandler*()->zoomItX(YBORDER_WIDTH),<br>
> size.height());    rowHeader->setPos(-rowHeader->width(), 0);<br>
> columnHeader->toolChanged("PanTool");<br>
> rowHeader->toolChanged("PanTool");        QGraphicsScene scene;<br>
> scene.addItem(canvas);    scene.addItem(columnHeader);<br>
> scene.addItem(rowHeader);    QGraphicsView view(&scene);<br>
> view.show();    qapp.exec();}<br>
><br>
><br>
> This portion of code can run and show a excel file. But when I try using<br>
> function: doc.createView().show, only tabbars and scrollbars shown. Sheet<br>
> area is completely black. I try using canvas, canvasWidget and<br>
> canvasController but it isn't successful.<br>
> Anyone can show me why it is and how to render the view to an image ?<br>
<br>
</div></div>Hi Tien,<br>
<br>
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.<br>

<br>
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.<br>

<br>
Here's some sample code written by Mani Chandrasekar for his <a href="http://conf.kde.in" target="_blank">conf.kde.in</a> presentation that shows how it works:<br>
<br>
you need to implement two classes (this is the absolute minimum):<br>
<br>
-------------<br>
<br>
KoAbstractApplicationWindow<br>
KoAbstractApplicationController<br>
<br>
<br>
MainWindow::MainWindow(QWidget *parent) :<br>
    QMainWindow(parent),<br>
    KoAbstractApplicationWindow((m_controller<br>
                                 = new MyApplicationController(this))),<br>
    ui(new Ui::MainWindow)<br>
{<br>
    ui->setupUi(this);<br>
<br>
}<br>
<br>
MainWindow::~MainWindow()<br>
{<br>
    delete ui;<br>
}<br>
<br>
----------------<br>
<br>
MyApplicationController::MyApplicationController(MainWindow *window)<br>
    : KoAbstractApplicationController(window),<br>
    m_window(window)<br>
{<br>
}<br>
<br>
QWidget * MyApplicationController::mainWindow() const<br>
{<br>
    return m_window;<br>
}<br>
<br>
void MyApplicationController::setCentralWidget(QWidget *widget)<br>
{<br>
    m_window->setCentralWidget(widget);<br>
}<br>
<br>
<br>
--------------------<br>
<br>
And then it's simply a matter of instantiating and calling the method to open a file:<br>
<div class="im"><br>
int main(int argc, char *argv[])<br>
{<br>
</div>    QApplication a(argc, argv);<br>
<br>
    MainWindow wnd;<br>
    wnd.show();<br>
<br>
    wnd.controller()->openDocument("/home/mani/Downloads/MicromaxMMX300G.ppt");<br>
    return a.exec();<br>
}<br>
<font color="#888888"><br>
--<br>
Boudewijn Rempt | <a href="http://www.valdyas.org" target="_blank">http://www.valdyas.org</a>, <a href="http://www.krita.org" target="_blank">http://www.krita.org</a><br>
_______________________________________________<br>
calligra-devel mailing list<br>
<a href="mailto:calligra-devel@kde.org">calligra-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/calligra-devel" target="_blank">https://mail.kde.org/mailman/listinfo/calligra-devel</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Do Huu Tien<br>Handphone No: 0972471786<br>Email: <a href="mailto:tiendh11986@gmail.com">tiendh11986@gmail.com</a><br>Y!M: dohuu_tien86<br>