~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipecanvas/ipecreatetext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2007-01-09 23:14:51 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20070109231451-3nd095g7ishc108l
Tags: 6.0pre27-3
* debian/gsfonts-fontmap.xml: New.  Fontmap for fonts from gsfonts package.
* debian/rules: Use gsfonts-fontmap.xml instead of tetex-fontmap.xml.
* debian/control: Add texlive-latex-base dependency as alternative to
  tetex-bin (for pdflatex) and replace tetex-extra by gsfonts (for font
  files).  Patch courtesy of Norbert Preining.  Closes: #378537.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/*
5
5
 
6
6
    This file is part of the extensible drawing editor Ipe.
7
 
    Copyright (C) 1993-2004  Otfried Cheong
 
7
    Copyright (C) 1993-2005  Otfried Cheong
8
8
 
9
9
    Ipe is free software; you can redistribute it and/or modify it
10
10
    under the terms of the GNU General Public License as published by
31
31
#include "ipecreatetext.h"
32
32
#include "ipecanvas.h"
33
33
 
34
 
#include <qevent.h>
35
 
#include <qpainter.h>
36
 
#include <qstring.h>
37
 
#include <qmultilineedit.h>
38
 
#include <qlabel.h>
 
34
#include <QEvent>
 
35
#include <QPainter>
 
36
#include <QString>
 
37
#include <QLabel>
 
38
#include <QMouseEvent>
 
39
#include <QPaintEvent>
 
40
#include <QTextDocumentFragment>
 
41
#include <QTextCharFormat>
 
42
#include <QTextCursor>
39
43
 
40
44
inline IpeString IpeQ(const QString &str)
41
45
{
42
 
  return IpeString(str.utf8());
 
46
  return IpeString(str.toUtf8());
43
47
}
44
48
 
45
49
inline QString QIpe(const IpeString &str)
54
58
*/
55
59
 
56
60
//! The argument \c data is only updated if the dialog is accepted.
57
 
IpeDialogCreateText::IpeDialogCreateText(QWidget* parent, QString caption,
58
 
                                   QString label, QString &data)
59
 
  : IpeDlgCreateText(parent, "dlgcreatetext", true), iData(data)
60
 
{
61
 
  setCaption(caption);
 
61
/*! This dialog will include the combobox for the text style. */
 
62
IpeDialogCreateText::IpeDialogCreateText(QWidget* /*parent*/, QString caption,
 
63
                                         QString label, QString &data,
 
64
                                         const IpeStyleSheet *sheet,
 
65
                                         IpeAttribute &style,
 
66
                                         IpeAttribute &size)
 
67
  : QDialog(), iData(data), iCurrentStyle(&style), iCurrentSize(&size)
 
68
{
 
69
  init(caption, label);
 
70
  sheet->AllNames(IpeAttribute::ETextStyle, iStyles);
 
71
  // make sure "default" is entry number 0
 
72
  for (IpeAttributeSeq::iterator it = iStyles.begin();
 
73
       it != iStyles.end(); ++it) {
 
74
    IpeString s = sheet->Repository()->String(*it);
 
75
    if (s == "default") {
 
76
      IpeAttribute t = *it;
 
77
      *it = iStyles[0];
 
78
      iStyles[0] = t;
 
79
      break;
 
80
    }
 
81
  }
 
82
  for (IpeAttributeSeq::const_iterator it = iStyles.begin();
 
83
       it != iStyles.end(); ++it) {
 
84
    IpeString s = sheet->Repository()->String(*it);
 
85
    iStyle->addItem(QIpe(s));
 
86
    if (*it == *iCurrentStyle)
 
87
      iStyle->setCurrentIndex(iStyle->count() - 1);
 
88
  }
 
89
  sheet->AllNames(IpeAttribute::ETextSize, iSizes);
 
90
  for (IpeAttributeSeq::const_iterator it = iSizes.begin();
 
91
       it != iSizes.end(); ++it) {
 
92
    IpeString s = sheet->Repository()->String(*it);
 
93
    iSize->addItem(QIpe(s));
 
94
    if (*it == *iCurrentSize)
 
95
      iSize->setCurrentIndex(iSize->count() - 1);
 
96
  }
 
97
}
 
98
 
 
99
//! The argument \c data is only updated if the dialog is accepted.
 
100
/*! This dialog will not include the text style selection or the text size. */
 
101
IpeDialogCreateText::IpeDialogCreateText(QWidget* /*parent*/, QString caption,
 
102
                                         QString label, QString &data)
 
103
  : QDialog(), iData(data), iCurrentStyle(0), iCurrentSize(0)
 
104
{
 
105
  init(caption, label);
 
106
  iStyle->hide();
 
107
  iSize->hide();
 
108
}
 
109
 
 
110
void IpeDialogCreateText::init(const QString &caption, const QString &label)
 
111
{
 
112
  setupUi(this);
 
113
  setWindowTitle(caption);
 
114
  connect(buttonOk, SIGNAL(clicked()), this, SLOT(UpdateData()));
62
115
  iLabel->setText(label);
63
 
  iEditor->setText(iData);
 
116
  QTextDocument *doc = new QTextDocument(iEditor);
 
117
  QTextCharFormat format;
 
118
  // format.setBackground(Qt::yellow);
 
119
  format.setFont(editorFont);
 
120
  QTextCursor cursor(doc);
 
121
  cursor.setBlockCharFormat(format);
 
122
  cursor.insertFragment(QTextDocumentFragment::fromPlainText(iData));
 
123
  iEditor->setDocument(doc);
 
124
  iEditor->setTextCursor(cursor);
64
125
  iEditor->setFocus();
65
 
#if 0
66
 
  iEditor->setFont(SPreferences::Static()->iTextFont);
67
 
#endif
68
126
}
69
127
 
70
128
void IpeDialogCreateText::UpdateData()
71
129
{
72
 
  iData = iEditor->text();
 
130
  iData = iEditor->toPlainText();
 
131
  if (iCurrentStyle) {
 
132
    if (iStyle->currentIndex() == 0)
 
133
      *iCurrentStyle = IpeAttribute(); // null style
 
134
    else
 
135
      *iCurrentStyle = iStyles[iStyle->currentIndex()];
 
136
  }
 
137
  if (iCurrentSize)
 
138
    *iCurrentSize = iSizes[iSize->currentIndex()];
73
139
}
74
140
 
75
 
void IpeDialogCreateText::FlushLeft()
 
141
void IpeDialogCreateText::SetEditorFont(const QString &font)
76
142
{
77
 
  QString s = iEditor->text().stripWhiteSpace();
78
 
  iEditor->setText("\\begin{flushleft}\n" + s + "\n\\end{flushleft}\n");
 
143
  if (!font.isEmpty()) {
 
144
    editorFont.fromString(font);
 
145
  } else
 
146
    editorFont = QApplication::font();
79
147
}
80
148
 
 
149
QFont IpeDialogCreateText::editorFont;
 
150
 
81
151
// --------------------------------------------------------------------
82
152
 
83
153
/*! \class CreateText
95
165
 
96
166
void IpeCreateText::New(QMouseEvent *, IpeCanvas *canvas,
97
167
                        IpeOverlayServices *services, TMode mode,
98
 
                        IpeRect *rect, const char *init)
 
168
                        IpeRect *rect)
99
169
{
100
170
  IpeVector pos = canvas->Pos();
101
171
  QString text;
102
 
  if (init)
103
 
    text = init;
104
 
  IpeDialogCreateText *dialog =
105
 
    new IpeDialogCreateText(canvas, QObject::tr("Create text object"),
106
 
                         (mode == EMath ?
107
 
                          QObject::tr("Enter formula (LaTeX source)") :
108
 
                          QObject::tr("Enter text (LaTeX source)")), text);
 
172
  IpeAttribute currentStyle;
 
173
  IpeAttribute currentSize;
 
174
  IpeDialogCreateText *dialog = 0;
 
175
  if (rect && mode == EMinipage) {
 
176
    dialog = new
 
177
      IpeDialogCreateText(canvas, QObject::tr("Create text object"),
 
178
                          QObject::tr("Enter text (LaTeX source)"), text,
 
179
                          services->OvSvcStyleSheet(),
 
180
                          currentStyle, currentSize);
 
181
  } else {
 
182
    dialog = new
 
183
      IpeDialogCreateText(canvas, QObject::tr("Create text object"),
 
184
                          (mode == EMath ?
 
185
                           QObject::tr("Enter formula (LaTeX source)") :
 
186
                           QObject::tr("Enter text (LaTeX source)")), text);
 
187
  }
109
188
 
110
189
  if (dialog->exec() == QDialog::Accepted) {
111
 
    text = text.stripWhiteSpace();
 
190
    text = text.trimmed();
112
191
    if (!text.isEmpty()) {
113
192
      IpeString data = IpeQ(text);
114
193
      if (mode == EMath)
115
194
        data = IpeString("$") + data + "$";
116
195
      IpeText *obj;
117
 
      if (rect && mode == EMinipage)
 
196
      if (rect && mode == EMinipage) {
118
197
        obj = new IpeText(services->OvSvcAttributes(),
119
198
                          data, rect->TopLeft(),
120
199
                          IpeText::ETextbox, rect->Width());
121
 
      else
 
200
        obj->SetStyle(currentStyle);
 
201
        obj->SetSize(currentSize);
 
202
      } else
122
203
        obj = new IpeText(services->OvSvcAttributes(),
123
204
                          data, pos, IpeText::ELabel);
124
 
 
125
205
      services->OvSvcAddObject(obj);
126
206
      canvas->Update();
127
207
    }
128
208
  }
129
209
}
130
210
 
131
 
bool IpeCreateText::Edit(IpeText *obj, const IpeStyleSheet *)
 
211
bool IpeCreateText::Edit(IpeText *obj, const IpeStyleSheet *sheet)
132
212
{
133
213
  QString text;
134
214
  text = QIpe(obj->Text());
135
 
  IpeDialogCreateText *dialog =
136
 
    new IpeDialogCreateText(0, QObject::tr("Edit text object"),
137
 
                         QObject::tr("Edit LaTeX source"), text);
 
215
  IpeDialogCreateText *dialog = 0;
 
216
  IpeAttribute style = obj->Style();
 
217
  IpeAttribute size = obj->Size();
 
218
  if (obj->IsMiniPage()) {
 
219
    dialog = new IpeDialogCreateText(0, QObject::tr("Edit text object"),
 
220
                                     QObject::tr("Edit LaTeX source"), text,
 
221
                                     sheet, style, size);
 
222
  } else
 
223
    dialog = new IpeDialogCreateText(0, QObject::tr("Edit text object"),
 
224
                                     QObject::tr("Edit LaTeX source"), text);
138
225
  if (dialog->exec() == QDialog::Accepted) {
139
 
    text = text.stripWhiteSpace();
 
226
    text = text.trimmed();
140
227
    if (!text.isEmpty()) {
141
228
      obj->SetText(IpeQ(text));
 
229
      obj->SetStyle(style);
 
230
      obj->SetSize(size);
142
231
      return true;
143
232
    }
144
233
  }
174
263
    wid = -wid;
175
264
  }
176
265
  QString text;
 
266
  IpeAttribute style;
 
267
  IpeAttribute size;
177
268
  IpeDialogCreateText *dialog =
178
269
    new IpeDialogCreateText(iCanvas, QObject::tr("Create text object"),
179
 
                         QObject::tr("Enter LaTeX source"), text);
 
270
                            QObject::tr("Enter LaTeX source"), text,
 
271
                            iServices->OvSvcStyleSheet(), style, size);
180
272
  if (dialog->exec() == QDialog::Accepted) {
181
 
    text = text.stripWhiteSpace();
 
273
    text = text.trimmed();
182
274
    if (!text.isEmpty()) {
183
275
      IpeText *obj = new IpeText(iServices->OvSvcAttributes(),
184
276
                                 IpeQ(text), iV[0], IpeText::EMinipage, wid);
 
277
      obj->SetStyle(style);
 
278
      obj->SetSize(size);
185
279
      iServices->OvSvcAddObject(obj);
186
280
    }
187
281
  }