![]() | Adding code |
| Prev | Next |
You should be able to compile and install your widget now, but its functionality is limited. For now you can't use any DCOP methods with it (except very general functions working for any widget, such as type or children).
DCOP method is a method to manipulate widget. For example, for our ColorCombo widget we may want to use text and setText methods to get/set current color of the widget. Then, we can use the methods like that:
ColorCombo.setText(newcolor) color = ColorCombo.text
Let's look at the end part of colorcombo.cpp.
bool ColorCombo::isFunctionSupported(int f)
{
return false;
}
QString ColorCombo::handleDCOP(int function, const QStringList& args)
{
return QString::null;
}
The first function checks whether appropriate function is supported by the widget. Let's change it to:
bool ColorCombo::isFunctionSupported(int f)
{
return f == DCOP::text || f == DCOP::setText;
}
Now we need to add the code to actually handle these two methods. Let's put the code in the second method:
QString ColorCombo::handleDCOP(int function, const QStringList& args)
{
switch (function)
{
case DCOP::text:
return color().name();
case DCOP::setText:
setColor(args[0]);
break;
default:
break;
}
return QString::null;
}
You can find the list of defined DCOP functions in specials.h. You can also use Function
Browser to see expected syntax for those functions. Please try to use the syntax used by standard Kommander
widgets - this will make using your widget easier.
If default functions are not enough, you can define your own. For example, for DualColorButton based on KDualColorButton we may need function setColors taking two color parameters.
#define DCOP_SET_COLOR 1001
DualColorCombo::DualColorCombo(QWidget *a_parent, const char *a_name)
.........
SpecialInformation::insert(DCOP_SET_COLOR, "setColors(QString color1, QString, color2)",
"Sets foreground and background colors."), 2);
Parameters of SpecialInformation::insert function are as follows:
| Prev | Home | Next |
| Compilation | Up | Installation |