Pārlūkot izejas kodu

Allow QTabBar creation from XML configuration files

Neal Wilson 8 gadus atpakaļ
vecāks
revīzija
b3de80261a
1 mainītis faili ar 78 papildinājumiem un 0 dzēšanām
  1. 78
    0
      src/typica.w

+ 78
- 0
src/typica.w Parādīt failu

@@ -4917,6 +4917,80 @@ void populateStackedLayout(QDomElement element, QStack<QWidget *> *widgetStack,
4917 4917
     }
4918 4918
 }
4919 4919
 
4920
+@ A common use of stacked layouts is in the creation of tabbed interfaces, but
4921
+there are also many uses in \pn{} where the tabs are not required. Therefore,
4922
+tab bar creation requires a separate XML element.
4923
+
4924
+@<Additional box layout elements@>=
4925
+else if(currentElement.tagName() == "tabbar")
4926
+{
4927
+	addTabBarToLayout(currentElement, widgetStack, layoutStack);
4928
+}
4929
+
4930
+@ The function used to create this follows the usual pattern.
4931
+
4932
+@<Functions for scripting@>=
4933
+void addTabBarToLayout(QDomElement element, QStack<QWidget*> *, QStack<QLayout*> *layoutStack)
4934
+{
4935
+	QBoxLayout *layout = qobject_cast<QBoxLayout *>(layoutStack->top());
4936
+	QTabBar *widget = new QTabBar;
4937
+	layout->addWidget(widget);
4938
+	if(!element.attribute("id").isEmpty())
4939
+	{
4940
+		widget->setObjectName(element.attribute("id"));
4941
+	}
4942
+}
4943
+
4944
+@ Rather than define the tab set in XML, this is left to the host environment.
4945
+This means that some additional scripting support is required.
4946
+
4947
+@<Set up the scripting engine@>=
4948
+constructor = engine->newFunction(constructQTabBar);
4949
+value = engine->newQMetaObject(&QTabBar::staticMetaObject, constructor);
4950
+engine->globalObject().setProperty("QTabBar", value);
4951
+
4952
+@ The constructor is trivial.
4953
+
4954
+@<Functions for scripting@>=
4955
+QScriptValue constructQTabBar(QScriptContext *, QScriptEngine *engine)
4956
+{
4957
+	QScriptValue object = engine->newQObject(new QTabBar);
4958
+	setQTabBarProperties(object, engine);
4959
+	return object;
4960
+}
4961
+
4962
+@ There are many functions that I might want to some day add support for, but
4963
+the immediate need is just creating the tabs in the first place.
4964
+
4965
+@<Functions for scripting@>=
4966
+void setQTabBarProperties(QScriptValue value, QScriptEngine *engine)
4967
+{
4968
+	setQWidgetProperties(value, engine);
4969
+	value.setProperty("addTab", engine->newFunction(QTabBar_addTab));
4970
+}
4971
+
4972
+QScriptValue QTabBar_addTab(QScriptContext *context, QScriptEngine *)
4973
+{
4974
+	QTabBar *self = getself<QTabBar *>(context);
4975
+	if(context->argumentCount() > 0)
4976
+	{
4977
+		self->addTab(argument<QString>(0, context));
4978
+	}
4979
+	else
4980
+	{
4981
+		context->throwError("Incorrect number of arguments passed to "@|
4982
+		                    "QTabBar::addTab().");
4983
+	}
4984
+	return QScriptValue();
4985
+}
4986
+
4987
+@ Function prototypes are needed.
4988
+
4989
+@<Function prototypes for scripting@>=
4990
+QScriptValue constructQTabBar(QScriptContext *context, QScriptEngine *engine);
4991
+void setQTabBarProperties(QScriptValue value, QScriptEngine *engine);
4992
+QScriptValue QTabBar_addTab(QScriptContext *context, QScriptEngine *engine);
4993
+
4920 4994
 @ Using a grid layout is a bit different from using a box layout. Child elements
4921 4995
 with various attributes are required to take full advantage of this layout type.
4922 4996
 All direct children of a grid layout element should be {\tt <row>} elements
@@ -6385,6 +6459,10 @@ else if(className == "QSvgWidget")
6385 6459
 {
6386 6460
     setQSvgWidgetProperties(value, engine);
6387 6461
 }
6462
+else if(className == "QTabBar")
6463
+{
6464
+	setQTabBarProperties(value, engine);
6465
+}
6388 6466
 
6389 6467
 @ In the list of classes, the SaltTable entry is for a class which does not
6390 6468
 strictly exist on its own. It is, however, useful to provide some custom

Notiek ielāde…
Atcelt
Saglabāt