summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 5d0c6e4..5b1aa7e 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -164,49 +164,72 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name
164DrawPadCanvas::~DrawPadCanvas() 164DrawPadCanvas::~DrawPadCanvas()
165{ 165{
166} 166}
167 167
168void DrawPadCanvas::load(QIODevice* ioDevice) 168void DrawPadCanvas::load(QIODevice* ioDevice)
169{ 169{
170 QTextStream textStream(ioDevice); 170 QTextStream textStream(ioDevice);
171 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 171 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
172 172
173 QXmlInputSource xmlInputSource(textStream); 173 QXmlInputSource xmlInputSource(textStream);
174 QXmlSimpleReader xmlSimpleReader; 174 QXmlSimpleReader xmlSimpleReader;
175 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; 175 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
176 176
177 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); 177 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
178 xmlSimpleReader.parse(xmlInputSource); 178 xmlSimpleReader.parse(xmlInputSource);
179 179
180 m_pages = drawPadCanvasXmlHandler.pages(); 180 /*
181 * we could have loaded something from setDocument already
182 * due the delayed loading we need to make sure we do
183 * not lose pages
184 */
185 if ( !m_pages.isEmpty() ) {
186 QList<Page> pages = drawPadCanvasXmlHandler.pages();
187 QListIterator<Page> it( pages );
188 Page *p;
189 while ( ( p = it.current() ) ) {
190 ++it;
191 m_pages.append( p );
192 }
193 }else
194 m_pages = drawPadCanvasXmlHandler.pages();
195
196
181 197
182 if (m_pages.isEmpty()) { 198 if (m_pages.isEmpty()) {
183 m_pages.append(new Page("", 199 m_pages.append(new Page("",
184 clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), 200 clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0),
185 clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); 201 clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0)));
186 m_pages.current()->pixmap()->fill(Qt::white); 202 m_pages.current()->pixmap()->fill(Qt::white);
187 } 203 }
188 204
189 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); 205 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
190 viewport()->update(); 206 viewport()->update();
191 207
192 emit pagesChanged(); 208 emit pagesChanged();
193} 209}
194 210
195void DrawPadCanvas::initialPage() 211void DrawPadCanvas::initialPage()
196{ 212{
213 /*
214 * by setDocument we've set a page already so
215 * don't add an empty one. This comes due the delayed initialisation
216 */
217 if (!m_pages.isEmpty() )
218 return;
219
197 m_pages.append(new Page("", 220 m_pages.append(new Page("",
198 clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), 221 clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0),
199 clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); 222 clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0)));
200 //236, 232)); no more fixed sizes 223 //236, 232)); no more fixed sizes
201 224
202 m_pages.current()->pixmap()->fill(Qt::white); 225 m_pages.current()->pixmap()->fill(Qt::white);
203 226
204 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); 227 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
205 viewport()->update(); 228 viewport()->update();
206 229
207 emit pagesChanged(); 230 emit pagesChanged();
208} 231}
209 232
210void DrawPadCanvas::save(QIODevice* ioDevice) 233void DrawPadCanvas::save(QIODevice* ioDevice)
211{ 234{
212 QTextStream textStream(ioDevice); 235 QTextStream textStream(ioDevice);