~kst-plot/kst/debian-xenial

« back to all changes in this revision

Viewing changes to src/libkstapp/viewitem.h

  • Committer: Steven Benton
  • Date: 2012-11-04 22:45:35 UTC
  • mfrom: (1.2.10)
  • Revision ID: stevebenton@rogers.com-20121104224535-mnnvrp4mhvuz0h2p
* New upstream release.
* Non-maintainer upload.
* Remove patches that have been resolved upstream:
  - desktop-entry-contains-encoding-key.diff
  - desktop-entry-lacks-main-category.diff
    - upstream uses Education category rather than Graphics
  - fix-qreal-vs-double-for-arm.diff
* kst package Replaces and Conflicts with kst2 -- for old PPA users only

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
class DialogPage;
36
36
class ViewGridLayout;
37
37
class ViewItem;
 
38
class ViewItemDialog;
38
39
 
39
40
typedef QList<ViewItem *> ViewItemList;
40
41
 
42
43
{
43
44
  Q_OBJECT
44
45
  public:
 
46
    friend class DialogLauncherSI;
45
47
    enum GripMode {
46
48
      Move    = 1,
47
49
      Resize  = 2,
80
82
    void setTypeName(const QString& name) { _typeName = name; }
81
83
    const QString typeName() const { return _typeName; }
82
84
 
 
85
    // for dialog defaults
 
86
    virtual const QString defaultsGroupName() const = 0;
 
87
 
 
88
    // for view item dialogs
 
89
    virtual bool hasStroke() const {return false;}
 
90
    virtual bool hasBrush() const {return false;}
 
91
    virtual bool hasFont() const {return false;}
 
92
 
 
93
    virtual void setFont(const QFont &f, const QColor &c) {return;}
 
94
 
83
95
    View* view() const;
84
96
    void setView(View*);
85
97
 
86
98
    ViewItem *parentViewItem() const;
87
99
    void setParentViewItem(ViewItem *parent);
88
100
 
89
 
    virtual void updateRelativeSize();
 
101
    virtual void updateRelativeSize(bool force_data = false);
 
102
    virtual void updateDataRelativeRect(bool force = false);
90
103
 
91
104
    void moveTo(const QPointF& pos);
92
105
    
99
112
    void setRelativeCenter(const QPointF center) { _parentRelativeCenter = center; }
100
113
    QPointF relativePosition() const { return _parentRelativePosition; }
101
114
    void setRelativePosition(const QPointF pos) { _parentRelativePosition = pos; }
 
115
    void setRelativeLeft(const QPointF &pos) { _parentRelativeLeft = pos;}
 
116
    QPointF relativeRight() const {return _parentRelativeRight;}
 
117
    void setRelativeRight(const QPointF &pos) { _parentRelativeRight = pos;}
 
118
 
 
119
    QRectF dataRelativeRect() const { return _dataRelativeRect;}
 
120
    void setDataRelativeRect(QRectF r) { _dataRelativeRect = r;}
102
121
    
103
122
    qreal rotationAngle() const;
 
123
    qreal rotationAngleRadians() const;
104
124
 
105
125
    GripMode gripMode() const;
106
126
    void setGripMode(GripMode mode);
133
153
    bool isHighlighted() const { return _highlighted; }
134
154
    void setHighlighted(bool highlighted ) { _highlighted = highlighted; }
135
155
 
 
156
    bool lockPosToData() const {return _lockPosToData; }
 
157
 
136
158
    //NOTE This should be used in place of QGraphicsRectItem::setRect()...
137
159
    QRectF viewRect() const;
138
160
    void setViewRect(const QRectF &viewRect, bool automaticChange = false);
160
182
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
161
183
    virtual void paint(QPainter *painter);
162
184
 
 
185
    virtual void paintChildItems(QPainter &painter);
 
186
 
163
187
    virtual QList<DialogPage*> dialogPages() const { return QList<DialogPage*>(); }
164
188
 
165
189
    virtual QPointF centerOfRotation() const { return rect().center(); }
200
224
 
201
225
    CreationState creationState() const { return _creationState; }
202
226
 
203
 
    virtual void setItemPen(const QPen & pen) { setPen(pen); };
204
 
    virtual void setItemBrush(const QBrush & brush) { setBrush(brush); };
205
 
 
206
 
    template<class T> static QList<T *> getItems();
 
227
    virtual void setItemPen(const QPen & pen) { setPen(pen); }
 
228
    virtual void setItemBrush(const QBrush & brush) { setBrush(brush); }
 
229
 
 
230
    template<class T> static T* retrieveItem(const QString &name);
 
231
 
 
232
    template<class T> static QList<T *> getItems(bool include_hidden=false);
207
233
 
208
234
   // TODO: Remove, needed only for a Qt 4.3 bug workaround
209
235
    bool doSceneEvent(QGraphicsSceneContextMenuEvent *event) {
211
237
    }
212
238
 
213
239
    virtual bool isMaximized();
 
240
    QPointF dropHotSpot;
 
241
 
 
242
    void normalizePosition();
 
243
 
 
244
    virtual void applyDialogDefaultsFill();
 
245
    virtual void applyDialogDefaultsStroke();
 
246
    void applyDialogDefaultsLockPosToData();
 
247
 
 
248
    virtual void applyDataLockedDimensions();
 
249
    virtual bool dataPosLockable() const;
 
250
 
 
251
    QRectF parentRect() const;
214
252
 
215
253
  Q_SIGNALS:
216
254
    void geometryChanged();
217
255
    void creationComplete();
 
256
    void relativeSizeUpdated();
218
257
 
219
258
  /*FIXME these should be made private for only undo commands to access*/
220
259
  public Q_SLOTS:
222
261
    virtual void raise();
223
262
    virtual void lower();
224
263
    virtual void createAutoLayout();
225
 
    virtual void createCustomLayout();
 
264
    virtual void createProtectedLayout();
 
265
    virtual void createCustomLayout(int columns = 0);
226
266
    virtual void sharePlots(QPainter *painter, bool creation);
227
267
    virtual void remove();
228
268
    void resizeTopLeft(const QPointF &offset);
241
281
    void setBottom(qreal y);
242
282
    void setLeft(qreal x);
243
283
    void setRight(qreal x);
 
284
    void setLockPosToData(bool lockPosToData);
 
285
    virtual bool customDimensionsTab() {return false;}
244
286
 
 
287
    virtual void clearEditDialogPtr() {_editDialog = 0;}
245
288
  protected:
246
289
    virtual QPainterPath topLeftGrip() const;
247
290
    virtual QPainterPath topRightGrip() const;
266
309
 
267
310
  protected Q_SLOTS:
268
311
    virtual void creationPolygonChanged(View::CreationEvent event);
 
312
    void creationPolygonChangedFixedAspect(View::CreationEvent even, qreal aspect);
269
313
 
270
314
  protected:
271
315
    virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
285
329
    QAction *_raiseAction;
286
330
    QAction *_lowerAction;
287
331
    QAction *_autoLayoutAction;
 
332
    QAction *_protectedLayoutAction;
288
333
    QAction *_customLayoutAction;
 
334
    QAction *_lockPosToDataAction;
289
335
 
290
336
    bool _isXTiedZoom;
291
337
    bool _isYTiedZoom;
296
342
    void updateView();
297
343
 
298
344
  protected:
299
 
  public: // TODO why does View need it?
 
345
  public:
300
346
    virtual void updateChildGeometry(const QRectF &oldParentRect, const QRectF &newParentRect);
301
347
  protected:
302
348
    virtual QString _automaticDescriptiveName() const;
303
349
    virtual void _initializeShortName();
 
350
    QPointF dragStartPosition;
 
351
    void startDragging(QWidget *widget, const QPointF& hotspot);
 
352
    ActiveGrip _activeGrip;
 
353
    QRectF _dataRelativeRect;
 
354
    QPointF _originalPosition;
 
355
    QPointF _parentRelativeCenter;
 
356
    QPointF _parentRelativePosition;
 
357
    QPointF _parentRelativeLeft;
 
358
    QPointF _parentRelativeRight;
 
359
    qreal _parentRelativeHeight, _parentRelativeWidth;
 
360
 
304
361
 
305
362
  private:
306
363
    GripMode _gripMode;
321
378
    bool _acceptsContextMenuEvents;
322
379
    bool _updatingLayout;
323
380
    bool _highlighted;
324
 
    QPointF _originalPosition;
325
 
    QPointF _parentRelativeCenter;
326
 
    QPointF _parentRelativePosition;
327
381
    QRectF _originalRect;
328
382
    QTransform _originalTransform;
329
383
    QLineF _normalLine;
330
384
    QLineF _rotationLine;
331
 
    ActiveGrip _activeGrip;
332
385
    ActiveGrips _allowedGrips;
333
386
    QTransform _rotationTransform;
334
387
    QHash<QString, QAction*> _shortcutMap;
335
 
    qreal _parentRelativeHeight, _parentRelativeWidth;
 
388
 
 
389
    bool _lockPosToData;
336
390
 
337
391
    QSizeF _layoutMargins, _layoutSpacing;    
338
392
 
343
397
    // use setParentViewItem(ViewItem*)
344
398
    void setParentItem(QGraphicsItem*);
345
399
 
346
 
    QPointF dragStartPosition;
347
 
    void startDragging(QWidget *widget, const QPointF& hotspot);
348
 
 
 
400
    ViewItemDialog *_editDialog;
349
401
};
350
402
 
351
403
Q_DECLARE_OPERATORS_FOR_FLAGS(ViewItem::GripModes)
396
448
 
397
449
    virtual void undo();
398
450
    virtual void redo();
399
 
    void createLayout(int columns = 0);
400
 
 
 
451
    void createLayout(bool preserve = true, int columns = 0);
401
452
  private:
402
453
    QPointer<ViewGridLayout> _layout;
403
454
};
526
577
    virtual ~RotateCommand() {}
527
578
};
528
579
 
529
 
// FIXME: This returns a list of ungaurded pointers; if the object is deleted
530
 
// between when the list is aquired and when one of the pointers is de-referenced,
531
 
// there will be a crash.  They are unguarded, because they are normally held by the
532
 
// scene as unguarded pointers, so it is too late to add a guard.
533
 
// I can't see a way of fixing it easily.  The best option
534
 
// for now is to minimize the cross section of this: use the pointers
535
 
// immediately after getting them, and don't hold them waiting for the
536
 
// user to delete the object they refer to...  The user might still be able to arrange
537
 
// a crash, however.
 
580
 
538
581
template<class T>
539
 
QList<T *> ViewItem::getItems() {
 
582
QList<T *> ViewItem::getItems(bool include_hidden) {
540
583
  QList<T *> tItems;
541
584
  ViewItem *viewItem;
542
585
  T* tItem;
546
589
  for (int i_view = 0; i_view<views.count(); i_view++) {
547
590
    QList<QGraphicsItem*> items = views.at(i_view)->scene()->items();
548
591
    for (int i_item = 0; i_item<items.count(); i_item++) {
549
 
      viewItem = qgraphicsitem_cast<ViewItem *>(items[i_item]);
 
592
      viewItem = dynamic_cast<ViewItem *>(items[i_item]);
550
593
      tItem = dynamic_cast<T*>(viewItem);
551
 
      if (tItem) {
 
594
      if ((tItem) && (include_hidden || viewItem->isVisible())) {
552
595
        tItems.append(tItem);
553
596
      }
554
597
    }
556
599
  return tItems;
557
600
}
558
601
 
 
602
template<class T>
 
603
T* ViewItem::retrieveItem(const QString &name) {
 
604
  QList<T *> tItems = getItems<T>();
 
605
 
 
606
  int match = -1;
 
607
 
 
608
  if (name.isEmpty()) {
 
609
    return NULL;
 
610
  }
 
611
 
 
612
  QString shortName;
 
613
  QRegExp rx("(\\(|^)([A-Z]\\d+)(\\)$|$)");
 
614
  rx.indexIn(name);
 
615
  shortName = rx.cap(2);
 
616
 
 
617
  // 1) search for short names
 
618
  int size = tItems.size();
 
619
  for (int i = 0; i < size; ++i) {
 
620
    if (tItems.at(i)->shortName()==shortName)
 
621
      return tItems.at(i);
 
622
  }
 
623
  // 3) search for descriptive names: must be unique
 
624
  for (int i = 0; i < size; ++i) {
 
625
    if (tItems.at(i)->descriptiveName() == name) {
 
626
      if (match != -1)
 
627
        return NULL; // not unique, so... no match
 
628
      match = i;
 
629
    }
 
630
  }
 
631
 
 
632
  if (match >-1)
 
633
    return tItems.at(match);
 
634
 
 
635
  return NULL;
 
636
}
 
637
 
 
638
 
559
639
class MimeDataViewItem : public QMimeData
560
640
{
561
641
  Q_OBJECT