[Kst] extragear/graphics/kst/kst

Rick Chern rchern at interchange.ubc.ca
Tue Aug 16 21:06:44 CEST 2005


SVN commit 449799 by rchern:

- checkbox to auto-resize text labels to fit text
- horizontal, vertical justification options for labels

 M  +27 -1     ksteditviewobjectdialog_i.cpp  
 M  +2 -0      ksteditviewobjectdialog_i.h  
 M  +8 -1      kstgfxtextmousehandler.cpp  
 M  +87 -2     kstviewlabel.cpp  
 M  +11 -0     kstviewlabel.h  
 M  +1 -0      kstviewobject.cpp  


--- trunk/extragear/graphics/kst/kst/ksteditviewobjectdialog_i.cpp #449798:449799
@@ -166,7 +166,19 @@
           // insert a font combo box
           propertyWidget = new KFontCombo(_propertiesFrame, (propertyName+","+"currentText").latin1());
           propertyWidget->setProperty("currentText", _viewObject->property(property->name()));  
-        } 
+        } else if (widgetType == "HJustifyCombo") {
+          // insert a combo box filled with horizontal justifications
+          QComboBox* combo = new QComboBox(_propertiesFrame, (propertyName+","+"currentItem").latin1());
+          fillHJustifyWidget(combo);
+          propertyWidget = combo;
+          propertyWidget->setProperty("currentItem", _viewObject->property(property->name()));
+        } else if (widgetType == "VJustifyCombo") {
+          // insert a combo box filled with vertical justifications
+          QComboBox* combo = new QComboBox(_propertiesFrame, (propertyName+","+"currentItem").latin1());
+          fillVJustifyWidget(combo);
+          propertyWidget = combo;
+          propertyWidget->setProperty("currentItem", _viewObject->property(property->name()));
+        }
         
         // also set any additional properties specified by metaData
         for (QMap<QString, QVariant>::iterator it = metaData.begin(); it != metaData.end(); ++it) {
@@ -222,6 +234,20 @@
 }
 
 
+void KstEditViewObjectDialogI::fillHJustifyWidget(QComboBox* widget) {
+  widget->insertItem(i18n("Left"));
+  widget->insertItem(i18n("Right"));
+  widget->insertItem(i18n("Center")); 
+}
+    
+
+void KstEditViewObjectDialogI::fillVJustifyWidget(QComboBox* widget) {
+  widget->insertItem(i18n("Top"));
+  widget->insertItem(i18n("Bottom"));
+  widget->insertItem(i18n("Center")); 
+}
+
+
 void KstEditViewObjectDialogI::okClicked() {
   if (_viewObject) {
     // get all the properties and set them
--- trunk/extragear/graphics/kst/kst/ksteditviewobjectdialog_i.h #449798:449799
@@ -39,6 +39,8 @@
     void clearWidgets();
     
     void fillPenStyleWidget(QComboBox* widget);
+    void fillHJustifyWidget(QComboBox* widget);
+    void fillVJustifyWidget(QComboBox* widget);
     
     KstViewObjectPtr _viewObject; // the view object we are currently editing
     KstTopLevelViewPtr _top; // the top level view that invoked this dialog
--- trunk/extragear/graphics/kst/kst/kstgfxtextmousehandler.cpp #449798:449799
@@ -25,6 +25,13 @@
 
 KstGfxTextMouseHandler::KstGfxTextMouseHandler(KstTopLevelViewPtr top)
   : KstGfxMouseHandler(top) {
+ 
+  // initial default settings before any sticky settings
+  KstViewLabelPtr defaultLabel = new KstViewLabel("Text");
+  defaultLabel->setAutoResize(true);
+  defaultLabel->setForegroundColor(Qt::black);
+  defaultLabel->setBackgroundColor(Qt::white);
+  _defaultObject = KstViewObjectPtr(defaultLabel); 
 }  
 
 
@@ -64,7 +71,7 @@
   // once released, create a new text object and popup the edit dialog
   if (!_cancelled) {
     KstViewLabelPtr label = new KstViewLabel("Text");
-    label->setAutoResize(true);
+    copyDefaults(KstViewObjectPtr(label));
     _top->appendChild(KstViewObjectPtr(label));
     label->move(_prevBand.topLeft());
     label->resize(_prevBand.size());
--- trunk/extragear/graphics/kst/kst/kstviewlabel.cpp #449798:449799
@@ -98,8 +98,6 @@
     }
     n = n.nextSibling();      
   }
-  
-  _autoResize = true;
 }
 
 
@@ -522,6 +520,16 @@
     map.insert(QString("_kst_widgetType"), QString("QCheckBox"));
     map.insert(QString("_kst_label"), i18n(""));
     map.insert(QString("text"), i18n("Transparent fill"));   
+  } else if (propertyName == "horizJustify") {
+    map.insert(QString("_kst_widgetType"), QString("HJustifyCombo"));
+    map.insert(QString("_kst_label"), i18n("Horizontal Justification"));
+  } else if (propertyName == "vertJustify") {
+    map.insert(QString("_kst_widgetType"), QString("VJustifyCombo"));
+    map.insert(QString("_kst_label"), i18n("Vertical Justification"));
+  } else if (propertyName == "autoResize") {
+    map.insert(QString("_kst_widgetType"), QString("QCheckBox"));
+    map.insert(QString("_kst_label"), i18n(""));
+    map.insert(QString("text"), i18n("Resize label for text"));   
   }
   return map;
 }
@@ -554,5 +562,82 @@
   return KstViewObject::transparent();  
 }
 
+
+int KstViewLabel::horizJustifyWrap() const {
+  Q_UINT8 justify = KST_JUSTIFY_H(justification());
+  switch (justify) {
+    case KST_JUSTIFY_H_LEFT:
+      return 0;
+      break;
+    case KST_JUSTIFY_H_RIGHT:
+      return 1;
+      break;
+    case KST_JUSTIFY_H_CENTER:
+      return 2;
+      break;
+    default:
+      return 0;  
+  }
+}
+
+
+void KstViewLabel::setHorizJustifyWrap(int justify) {
+  Q_UINT8 justifySet;
+  
+  switch (justify) {
+    case 0:
+      justifySet = KST_JUSTIFY_H_LEFT;
+      break;  
+    case 1:
+      justifySet = KST_JUSTIFY_H_RIGHT;
+      break;
+    case 2:
+      justifySet = KST_JUSTIFY_H_CENTER;
+      break;
+    default:
+      justifySet = KST_JUSTIFY_H_LEFT;
+  }
+  setJustification(SET_KST_JUSTIFY(justifySet, KST_JUSTIFY_V(justification())));
+}
+    
+        
+int KstViewLabel::vertJustifyWrap() const {
+  Q_UINT8 justify = KST_JUSTIFY_V(justification());
+  switch (justify) {
+    case KST_JUSTIFY_V_TOP:
+      return 0;
+      break;
+    case KST_JUSTIFY_V_BOTTOM:
+      return 1;
+      break;
+    case KST_JUSTIFY_V_CENTER:
+      return 2;
+      break;
+    default:
+      return 0;  
+  }
+}
+
+
+void KstViewLabel::setVertJustifyWrap(int justify) {
+  Q_UINT8 justifySet;
+  
+  switch (justify) {
+    case 0:
+      justifySet = KST_JUSTIFY_V_TOP;
+      break;  
+    case 1:
+      justifySet = KST_JUSTIFY_V_BOTTOM;
+      break;
+    case 2:
+      justifySet = KST_JUSTIFY_V_CENTER;
+      break;
+    default:
+      justifySet = KST_JUSTIFY_V_TOP;
+  }
+  setJustification(SET_KST_JUSTIFY(KST_JUSTIFY_H(justification()), justifySet));
+}
+    
+
 #include "kstviewlabel.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstviewlabel.h #449798:449799
@@ -36,6 +36,9 @@
   Q_PROPERTY(int dataPrecision READ dataPrecision WRITE setDataPrecision)
   Q_PROPERTY(uint fontSize READ fontSize WRITE setFontSize);
   Q_PROPERTY(bool transparent READ transparent WRITE setTransparent)
+  Q_PROPERTY(int horizJustify READ horizJustifyWrap WRITE setHorizJustifyWrap)
+  Q_PROPERTY(int vertJustify READ vertJustifyWrap WRITE setVertJustifyWrap)
+  Q_PROPERTY(bool autoResize READ autoResize WRITE setAutoResize)
   public:
     KstViewLabel(const QString& txt, KstLJustifyType justify = 0L, float rotation = 0.0);
     KstViewLabel(const QDomElement& e);
@@ -49,6 +52,14 @@
 
     void setJustification(KstLJustifyType Justify);
     KstLJustifyType justification() const { return _justify; }
+    
+    // wraps for Q_PROPERTIES
+    int horizJustifyWrap() const;
+    // 0 = left, 1 = right, 2 = centre
+    void setHorizJustifyWrap(int justify);
+    int vertJustifyWrap() const;
+    // 0 = top, 1 = bottom, 2 = centre
+    void setVertJustifyWrap(int justify);
 
     int ascent() const;
 
--- trunk/extragear/graphics/kst/kst/kstviewobject.cpp #449798:449799
@@ -1495,6 +1495,7 @@
 
 
 QMap<QString, QVariant > KstViewObject::widgetHints(const QString& propertyName) const {
+  Q_UNUSED(propertyName)
   return QMap<QString, QVariant>();
 }
 


More information about the Kst mailing list