~ubuntu-branches/ubuntu/quantal/cantor/quantal

« back to all changes in this revision

Viewing changes to src/worksheet.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: package-import@ubuntu.com-20111215141754-mpepwpmr42120lpf
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "worksheetentry.h"
33
33
#include "commandentry.h"
34
34
#include "textentry.h"
 
35
#include "imageentry.h"
 
36
#include "pagebreakentry.h"
 
37
#include "latexentry.h"
35
38
 
36
39
#include "resultproxy.h"
37
40
#include "animationhandler.h"
61
64
 
62
65
#include "worksheet.h"
63
66
#include "settings.h"
 
67
#include "formulatextobject.h"
64
68
 
65
69
 
66
70
Worksheet::Worksheet(Cantor::Backend* backend, QWidget* parent) : KRichTextWidget(parent)
84
88
 
85
89
    m_proxy=new ResultProxy(document());
86
90
    document()->documentLayout()->registerHandler(QTextFormat::ImageObject, new AnimationHandler(document()));
 
91
    document()->documentLayout()->registerHandler(FormulaTextObject::FormulaTextFormat, new FormulaTextObject());
87
92
 
 
93
    m_isPrinting=false;
88
94
    //postpone login, until everything is set up correctly
89
95
    m_loginFlag=true;
90
96
    QTimer::singleShot(0, this, SLOT(loginToSession()));
118
124
void Worksheet::print( QPrinter* printer )
119
125
{
120
126
    m_proxy->useHighResolution(true);
 
127
    m_isPrinting = true;
121
128
    foreach(WorksheetEntry* e, m_entries)
122
129
        e->update();
123
130
 
124
131
 
125
132
    KTextEdit::print(printer);
126
133
 
 
134
    m_isPrinting = false;
 
135
 
127
136
    m_proxy->useHighResolution(false);
128
137
    foreach(WorksheetEntry* e, m_entries)
129
138
        e->update();
130
139
 
131
140
}
132
141
 
 
142
bool Worksheet::isPrinting()
 
143
{
 
144
    return m_isPrinting;
 
145
}
 
146
 
133
147
bool Worksheet::event(QEvent* event)
134
148
{
135
149
    if (event->type() == QEvent::ShortcutOverride)
203
217
    const QTextCursor cursor = cursorForPosition(event->pos());
204
218
    WorksheetEntry* entry = entryAt(cursor);
205
219
 
206
 
    if (entry)
207
 
    {
208
 
        if (!entry->worksheetContextMenuEvent(event, cursor))
209
 
            KRichTextWidget::contextMenuEvent(event);
210
 
        if (entry != m_currentEntry)
211
 
            setCurrentEntry(entry);
212
 
    }
213
 
    else
 
220
    if (entry && entry != m_currentEntry)
 
221
        setCurrentEntry(entry);
 
222
    if (!entry || !entry->worksheetContextMenuEvent(event, cursor))
214
223
    {
215
224
        KMenu* defaultMenu = new KMenu(this);
216
225
 
225
234
        {
226
235
            defaultMenu->addAction(i18n("Append Command Entry"),this,SLOT(appendCommandEntry()),0);
227
236
            defaultMenu->addAction(i18n("Append Text Entry"),this,SLOT(appendTextEntry()),0);
 
237
            defaultMenu->addAction(i18n("Append Latex Entry"),this,SLOT(appendLatexEntry()),0);
 
238
            defaultMenu->addAction(i18n("Append Image"),this,SLOT(appendImageEntry()),0);
 
239
            defaultMenu->addAction(i18n("Append Page Break"),this,SLOT(appendPageBreakEntry()),0);
228
240
 
229
241
        }
230
242
        else
232
244
            setCurrentEntry(entryNextTo(cursor));
233
245
            defaultMenu->addAction(i18n("Insert Command Entry"),this,SLOT(insertCommandEntryBefore()),0);
234
246
            defaultMenu->addAction(i18n("Insert Text Entry"),this,SLOT(insertTextEntryBefore()),0);
 
247
            defaultMenu->addAction(i18n("Insert Latex Entry"),this,SLOT(insertLatexEntryBefore()),0);
 
248
            defaultMenu->addAction(i18n("Insert Image"),this,SLOT(insertImageEntryBefore()),0);
 
249
            defaultMenu->addAction(i18n("Insert Page Break"),this,SLOT(insertPageBreakEntryBefore()),0);
235
250
        }
236
251
 
237
252
        defaultMenu->popup(event->globalPos());
367
382
 
368
383
    switch(type)
369
384
    {
370
 
    case (TextEntry::Type):
371
 
        entry = new TextEntry(cursor, this);
372
 
    break;
373
 
    case (CommandEntry::Type):
374
 
        entry = new CommandEntry(cursor, this);
375
 
    break;
376
 
    default:
377
 
        entry = 0;
 
385
        case TextEntry::Type:
 
386
            entry = new TextEntry(cursor, this);
 
387
            break;
 
388
        case CommandEntry::Type:
 
389
            entry = new CommandEntry(cursor, this);
 
390
            break;
 
391
        case ImageEntry::Type:
 
392
            entry = new ImageEntry(cursor, this);
 
393
            break;
 
394
        case PageBreakEntry::Type:
 
395
            entry = new PageBreakEntry(cursor, this);
 
396
            break;
 
397
        case LatexEntry::Type:
 
398
            entry = new LatexEntry(cursor,this);
 
399
            break;
 
400
        default:
 
401
            entry = 0;
378
402
    }
379
403
 
380
404
    return entry;
416
440
   return appendEntry(TextEntry::Type);
417
441
}
418
442
 
 
443
 
 
444
WorksheetEntry* Worksheet::appendPageBreakEntry()
 
445
{
 
446
    return appendEntry(PageBreakEntry::Type);
 
447
}
 
448
 
 
449
WorksheetEntry* Worksheet::appendImageEntry()
 
450
{
 
451
   return appendEntry(ImageEntry::Type);
 
452
}
 
453
 
 
454
WorksheetEntry* Worksheet::appendLatexEntry()
 
455
{
 
456
    return appendEntry(LatexEntry::Type);
 
457
}
 
458
 
419
459
void Worksheet::appendCommandEntry(const QString& text)
420
460
{
421
461
    WorksheetEntry* entry=m_entries.last();
461
501
    return insertEntry(TextEntry::Type);
462
502
}
463
503
 
 
504
WorksheetEntry* Worksheet::insertImageEntry()
 
505
{
 
506
    return insertEntry(ImageEntry::Type);
 
507
}
 
508
 
464
509
WorksheetEntry* Worksheet::insertCommandEntry()
465
510
{
466
511
    return insertEntry(CommandEntry::Type);
467
512
}
468
513
 
 
514
WorksheetEntry* Worksheet::insertPageBreakEntry()
 
515
{
 
516
    return insertEntry(PageBreakEntry::Type);
 
517
}
 
518
 
 
519
WorksheetEntry* Worksheet::insertLatexEntry()
 
520
{
 
521
    return insertEntry(LatexEntry::Type);
 
522
}
 
523
 
469
524
void Worksheet::insertCommandEntry(const QString& text)
470
525
{
471
526
    WorksheetEntry* entry = insertCommandEntry();
511
566
    return insertEntryBefore(CommandEntry::Type);
512
567
}
513
568
 
 
569
WorksheetEntry* Worksheet::insertPageBreakEntryBefore()
 
570
{
 
571
    return insertEntryBefore(PageBreakEntry::Type);
 
572
}
 
573
 
 
574
WorksheetEntry* Worksheet::insertImageEntryBefore()
 
575
{
 
576
    return insertEntryBefore(ImageEntry::Type);
 
577
}
 
578
 
 
579
WorksheetEntry* Worksheet::insertLatexEntryBefore()
 
580
{
 
581
    return insertEntryBefore(LatexEntry::Type);
 
582
}
 
583
 
514
584
void Worksheet::interrupt()
515
585
{
516
586
    m_session->interrupt();
715
785
 
716
786
    }
717
787
 
718
 
    m_session=b->createSession();
719
 
    m_loginFlag=true;
720
 
    QTimer::singleShot(0, this, SLOT(loginToSession()));
721
 
 
722
 
    //Set the Highlighting, depending on the current state
723
 
    //If the session isn't logged in, use the default
724
 
    enableHighlighting( m_highlighter!=0 || (m_loginFlag && Settings::highlightDefault()) );
725
 
 
 
788
 
 
789
    //cleanup the worksheet and all it contains
 
790
    delete m_session;
 
791
    m_session=0;
 
792
    foreach(WorksheetEntry* entry, m_entries)
 
793
        delete entry;
726
794
    clear();
727
795
    m_entries.clear();
728
796
 
 
797
    m_session=b->createSession();
 
798
    m_loginFlag=true;
 
799
 
729
800
    kDebug()<<"loading entries";
730
801
    QDomElement expressionChild = root.firstChildElement();
731
802
    WorksheetEntry* entry;
740
811
        {
741
812
            entry = appendTextEntry();
742
813
            entry->setContent(expressionChild, file);
 
814
        }else if (tag == "Latex")
 
815
        {
 
816
            entry = appendLatexEntry();
 
817
            entry->setContent(expressionChild, file);
743
818
        }
 
819
        else if (tag == "PageBreak")
 
820
        {
 
821
            entry = appendPageBreakEntry();
 
822
            entry->setContent(expressionChild, file);
 
823
        }
 
824
        else if (tag == "Image")
 
825
        {
 
826
          entry = appendImageEntry();
 
827
          entry->setContent(expressionChild, file);
 
828
        }
744
829
 
745
830
        expressionChild = expressionChild.nextSiblingElement();
746
831
    }
747
832
 
 
833
    //login to the session, but let Qt process all the events in its pipeline
 
834
    //first.
 
835
    QTimer::singleShot(0, this, SLOT(loginToSession()));
 
836
 
 
837
    //Set the Highlighting, depending on the current state
 
838
    //If the session isn't logged in, use the default
 
839
    enableHighlighting( m_highlighter!=0 || (m_loginFlag && Settings::highlightDefault()) );
 
840
 
 
841
 
 
842
 
748
843
    emit sessionChanged();
749
844
}
750
845