[prev in list] [next in list] [prev in thread] [next in thread] 

List:       calligra-devel
Subject:    Re: Question about show view of calligra tables
From:       tien dh <tiendh11986 () gmail ! com>
Date:       2011-03-18 3:18:37
Message-ID: AANLkTi=EYAMwB9ev=_oXREtwyqGf4ipSZumxN5p+KFNE () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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 <boud@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: tiendh11986@gmail.com
Y!M: dohuu_tien86


[Attachment #5 (text/html)]

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">&lt;<a href="mailto:boud@valdyas.org">boud@valdyas.org</a>&gt;</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> &gt; Hi every one,<br>
&gt; Please help me on that problem, it&#39;s so difficult for me to solve:<br>
&gt;<br>
&gt;  int main(int argc, char** argv){    QApplication qapp(argc, argv);<br>
&gt; KComponentData cd(&quot;graphicsview-test&quot;);    Calligra::Tables::Doc \
doc;<br> &gt;   bool ok = \
doc.*openUrl*(KUrl(&quot;/home/excel_samples/Cash_Flow_Projection_Worksheet.xls&quot;));<br>
 &gt;    if (!ok) {        qDebug() &lt;&lt; &quot;failed to load&quot;;        \
return 0;<br> &gt; }    QFont font(KoGlobal::defaultFont());<br>
&gt; Calligra::Tables::CanvasItem* canvas = new<br>
&gt; Calligra::Tables::CanvasItem(&amp;doc);    QRect usedArea =<br>
&gt; canvas-&gt;*activeSheet*()-&gt;usedArea(true);    QSizeF<br>
&gt; size(canvas-&gt;*activeSheet*()-&gt;columnPosition(usedArea.right()+3),<br>
&gt; canvas-&gt;*activeSheet*()-&gt;rowPosition(usedArea.bottom()+5));<br>
&gt; canvas-&gt;setDocumentSize(size);    size =<br>
&gt; canvas-&gt;*zoomHandler*()-&gt;*documentToView*(size);<br>
&gt; canvas-&gt;resize(size);    canvas-&gt;setPos(0, 0);<br>
&gt; Calligra::Tables::ColumnHeaderItem* columnHeader =<br>
&gt; static_cast&lt;Calligra::Tables::ColumnHeaderItem*&gt;(canvas-&gt;*columnHeader*());<br>
 &gt;    static_cast&lt;QGraphicsWidget*&gt;(columnHeader)-&gt;resize(size.width(),<br>
 &gt; canvas-&gt;*zoomHandler*()-&gt;zoomItY(font.pointSizeF() + 3));<br>
&gt; columnHeader-&gt;setPos(0, -columnHeader-&gt;height());<br>
&gt; Calligra::Tables::RowHeaderItem* rowHeader =<br>
&gt; static_cast&lt;Calligra::Tables::RowHeaderItem*&gt;(canvas-&gt;*rowHeader*());<br>
 &gt;   static_cast&lt;QGraphicsWidget*&gt;(rowHeader)-&gt;resize(canvas-&gt;*zoomHandler*()-&gt;zoomItX(YBORDER_WIDTH),<br>
 &gt; size.height());    rowHeader-&gt;setPos(-rowHeader-&gt;width(), 0);<br>
&gt; columnHeader-&gt;toolChanged(&quot;PanTool&quot;);<br>
&gt; rowHeader-&gt;toolChanged(&quot;PanTool&quot;);        QGraphicsScene scene;<br>
&gt; scene.addItem(canvas);    scene.addItem(columnHeader);<br>
&gt; scene.addItem(rowHeader);    QGraphicsView view(&amp;scene);<br>
&gt; view.show();    qapp.exec();}<br>
&gt;<br>
&gt;<br>
&gt; This portion of code can run and show a excel file. But when I try using<br>
&gt; function: doc.createView().show, only tabbars and scrollbars shown. Sheet<br>
&gt; area is completely black. I try using canvas, canvasWidget and<br>
&gt; canvasController but it isn&#39;t successful.<br>
&gt; 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&#39;m not completely sure what you&#39;re tring to do here -- the mail came across \
a bit garbled. It looks like you&#39;re using the graphicsitem canvas, and in that \
case, you shouldn&#39;t use the createView() method since that creates a view. But \
what might be happening here is that your implementation of KoCanvasController \
doesn&#39;t size your canvas correctly. This is a bit fiddly, and we don&#39;t have \
any good example yet of how it should work. I&#39;m working on that, but I \
haven&#39;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&#39;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-&gt;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-&gt;setCentralWidget(widget);<br>
}<br>
<br>
<br>
--------------------<br>
<br>
And then it&#39;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()-&gt;openDocument(&quot;/home/mani/Downloads/MicromaxMMX300G.ppt&quot;);<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>



_______________________________________________
calligra-devel mailing list
calligra-devel@kde.org
https://mail.kde.org/mailman/listinfo/calligra-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic