Source Code (Use browser search to find items of interest.)
Class Index
krn'KTypeLayout (./kdenetwork/krn/typelayout.h:20)
class KTypeLayout: QObject
{
public:
/** Create a KTypeLayout inside of the parent widget
WARNING: parent's size will probably be affected, since
it will have to be at least large enough to contain its
children.
*/
KTypeLayout(){};
KTypeLayout(TLForm *parent);
virtual ~KTypeLayout();
/** No more children will be added, so geometry management can be done
Unlike the Qt layout managers, you CAN NOT add any more children
after this, or nasty things will happen.
*/
void activate();
/** Adds a widget to the layout.
Since KTypeLayout tends to shrink things to its minimum size and
then stretch them, you should be careful and set minimum/fixed/maximum
sizes for your widget.
Use only if none of the convenience addXXX functions works for you.
Returns a pointer to the TLobj with the widget.
*/
TLObj *addWidget(const char *ID,QWidget *w);
/** Adds a frame with an optional border and an optional title.
Until next end() call, widgets will be children of this widget.
If you specify a frame, it looks like Qt's GroupBox.
Returns a pointer to the TLForm object that's the new parent.
Groups should have a corresponding endGroup() call.
*/
TLForm *addGroup(const char *ID,const char *title="", bool frame=false);
/** Adds a "book" widget, with no pages.
Be careful not to add widgets before creating pages,
because geometry management will go nuts.
Books should have a corresponding endGroup() call.
*/
TLBook *addBook(const char *ID);
/** Adds a page to the current widget, that better be a book, or
you gonna be on BIIIIIIG trouble.
Pages should have a corresponding endGroup() call.
*/
TLForm *addPage(const char *ID,const char *title="");
/** Marks the end of a group (as added by addGroup).
This make following widgets children of the next outer group.
If there are no groups to end, it is the same as activate()..
*/
void endGroup();
/** Adds a label, with a minimum size at least enough for the text to fit
*/
TLObj *addLabel(const char *ID,const QString& text="");
/** Adds a button, with a minimum size at least enough for the text to fit
and also at least 75 pixels wide and 30 pixels tall.
This way you get a button that's as good looking enough as possible.
These buttons have a fixed size by default.
*/
TLObj *addButton(const char *ID,const QString& text="");
/** Adds a button with a pixmap instead of text
*/
TLObj *addButton(const char *ID,const QPixmap &p);
/** Adds a KColorButton
*/
TLObj *addColorButton(const char *ID,const QColor *c=0);
/**
Adds a Checkbox, with the usual respect for the environment
*/
TLObj *addCheckBox(const char *ID,const char *text="",bool checked=false);
/**
Adds a Radio button. GroupID is the group of buttons that are exclusive
(only one of them checked at a time).
The GroupID's are global like the IDs, so be careful not using the
same in two unrelated places.
id (lowercase) is the same as in QButtonGroup::insert.
*/
TLObj *addRadioButton(const char *ID,const char *GroupID,const char *text="",
bool checked=false,int id=-1);
/**
Adds a Line for data entry ( a QLineEdit).
text is the text it should contain.
maxlen is an enforced maximum length. It affects the data entered, not
the size of the widget, -1 means no limit.
*/
TLObj *addLineEdit(const char *ID,const char *text="",int maxlen=-1);
/**
Adds a Line for Integer data entry ( a KIntLineEdit).
text is the text it should contain.
maxlen is an enforced maximum length. It affects the data entered, not
the size of the widget, -1 means no limit.
*/
TLObj *addIntLineEdit(const char *ID,const char *text="",int maxlen=-1);
/**
Adds a ListBox.
contents is a list of textual contents. If you want to set contents
later, or use pixmaps, just set it to 0, and use findWidget() later.
minRows is the minimum number of rows that should be visible.
Think that if you get much below 5, then a ComboBox is probably a
better widget choice.
*/
TLObj *addListBox (const char *ID,QStrList *contents=0,int minRows=5);
/**
Similar to addListBox, but creates a QComboBox instead of a QListBox
if rw=TRUE, it's a editable QComboBox
*/
TLObj *addComboBox (const char *ID,QStrList *contents=0,bool rw=FALSE);
/** Ends a line of widgets, and starts a new one. Think about it
as pressing "return" in a word processor
*/
void newLine();
/** Skips a cell horizontally. Since widgets are loosely arranged
in a grid, you can use this command to leave a cell apparently empty.
Keep in mind that this won't affect that columns' minimum width at all.
*/
void skip();
/** Sets an object's alignment within his cell
It's like the alignment in Qt's QGridLayout::addWidget, except
that an alignment value of AlignLeft|AlignRight means "justify",
so the widget will stretch to fill its cell.
The same is valid for AlignTop|AlignBottom.
*/
static void setAlign (char *ID,int _align);
/** Makes a widget spawn vSpawn rows and hSpawn columns in the
layout grid.
Obviously, by default widgets occupy only one cell and have both
values set to 1.
*/
static void setSpawn (char *ID,int vSpawn=1,int hSpawn=1);
/** Returns a pointer to the TLObj that matches this ID.
That ID is stored in a dictionary that is shared by all KTypeLayouts,
so be careful not to create objects with identical IDs, or one of them
may become unaccessible!
However, having inaccessible Labels or groupboxes is usually not
a big problem.
You can access the widget as TLObj->widget, etcetera.
*/
static TLObj *findObject(const char *_ID);
/* Returns a pointer to the QWidget created by one of the add...
commands above identified with ID.
The kind of widget depends basically on how you created it,
so a cast will most likely be necessary to access some functionality.
Returns 0 if it can't find ID, so check that pointer!.
*/
static QWidget *findWidget(const char *_ID);
QList < QList <TLObj> > rows;
QStack <TLForm> windowStack;
QGridLayout *grid;
int outBorder;
int inBorder;
protected:
QWidget *widget;
TLForm *parent;
TLObj *lastobj;
QString path;
virtual void end();
};
/** Special layout for book widgets. It just sets the widget's
minimum size big enough to hold the largest of its pages.
*/
krn'KTypeLayout::KTypeLayout() (./kdenetwork/krn/typelayout.cpp:22)
KTypeLayout::KTypeLayout(TLForm *_parent)
{
objDict.insert(_parent->ID,parent);
outBorder=3;
inBorder=4;
parent=_parent;
widget=parent->widget;
path=parent->ID+".";
windowStack.push(parent);
lastobj=parent;
rows.append(new QList <TLObj>);
}
krn'KTypeLayout::~KTypeLayout() (./kdenetwork/krn/typelayout.cpp:35)
KTypeLayout::~KTypeLayout()
{
}
krn'KTypeLayout::activate() (./kdenetwork/krn/typelayout.cpp:39)
void KTypeLayout::activate()
{
while (!windowStack.isEmpty())
{
endGroup();
}
}
krn'KTypeLayout::endGroup() (./kdenetwork/krn/typelayout.cpp:47)
void KTypeLayout::endGroup()
{
TLForm *f=windowStack.pop();
f->layout->end();
}
krn'KTypeLayout::end() (./kdenetwork/krn/typelayout.cpp:53)
void KTypeLayout::end()
{
QList <TLObj> *row;
TLObj *o;
uint y=0,x=0;
uint maxH=0,acH=10;
uint maxw=0;
//First lets see if wee need aditional rows
int slacky=0;
for (row=rows.first(); row!=0; row=rows.next(),y++)
{
for ( o=row->first(); o!=0;o=row->next())
{
if ( (y+o->height) > (slacky+rows.count()) )
{
slacky=(y+o->height)-rows.count();
}
}
}
//Now lets look for aditional columns
uint lens[rows.count()+slacky];
for (uint il=0;il<rows.count()+slacky;il++)
{
lens[il]=0;
}
y=0;
for (row=rows.first(); row!=0; row=rows.next(),y++)
{
for ( o=row->first(); o!=0;o=row->next())
{
for (int ih=0;ih<o->height;ih++)
lens[y+ih]+=o->width;
}
}
for (uint il=0;il<rows.count()+slacky;il++)
{
if (lens[il]>maxw)
maxw=lens[il];
}
for (QList <TLObj> *l=rows.first();l!=0;l=rows.next())
if (maxw < l->count())
maxw=l->count();
for (uint il=0;il<rows.count()+slacky;il++)
{
if (lens[il]>maxw)
maxw=lens[il];
}
grid=new QGridLayout (widget,rows.count()+slacky,
maxw,outBorder,inBorder);
bool occupied[maxw][rows.count()+slacky];
for (x=0;x<maxw;x++)
for (y=0;y<rows.count()+slacky;y++)
occupied[x][y]=false;
y=0;x=0;
for (row=rows.first(); row!=0; row=rows.next(),y++)
{
x=0;
for ( o=row->first(); o!=0;o=row->next(),x++)
{
while (occupied[x][y])
x++;
if ((o->width==1)&&(o->height==1))
{
grid->addWidget(o->widget,y,x,o->align);
occupied[x][y]=true;
}
else
{
grid->addMultiCellWidget(o->widget,y,y+o->height-1
,x,x+o->width-1,o->align);
for (int ix=0;ix<o->width;ix++)
for (int iy=0;iy<o->height;iy++)
{
occupied[x+ix][y+iy]=true;
}
}
uint tmaxH=o->widget->minimumSize().height();
if (tmaxH>maxH)
maxH=tmaxH;
}
acH+=maxH+inBorder;
}
acH+=parent->vslack;
widget->setMinimumHeight(acH);
grid->activate();
widget->resize(widget->minimumSize());
}
krn'KTypeLayout::addWidget() (./kdenetwork/krn/typelayout.cpp:152)
TLObj *KTypeLayout::addWidget(const char *ID,QWidget *w)
{
TLObj *o;
o=new TLObj(ID);
o->widget=w;
o->path=path;
windowStack.top()->layout->rows.last()->append(o);
objDict.insert(ID,o);
o->align=AlignCenter;
return o;
}
krn'KTypeLayout::addGroup() (./kdenetwork/krn/typelayout.cpp:164)
TLForm *KTypeLayout::addGroup(const char *ID,const char *title, bool frame)
{
QWidget *g;
if (frame)
g=new QGroupBox(title,windowStack.top()->widget);
else
g=new QWidget(windowStack.top()->widget);
g->show();
TLForm *o=new TLForm(ID,"",g);
if (frame)
{
int h=g->fontMetrics().height();
o->vslack=h;
o->layout->outBorder=h;
}
o->path=path;
windowStack.top()->layout->rows.last()->append(o);
path=path+ID+".";
windowStack.push(o);
objDict.insert(ID,o);
return o;
}
krn'KTypeLayout::addLabel() (./kdenetwork/krn/typelayout.cpp:190)
TLObj *KTypeLayout::addLabel(const char *ID,const QString &text)
{
QWidget *g;
QLabel *l=new QLabel(text,windowStack.top()->widget);
g=l;
g->show();
g->setMinimumWidth(l->fontMetrics().width(text)+6);
g->setMinimumHeight(l->fontMetrics().height());
return addWidget(ID,g);
}
krn'KTypeLayout::addButton() (./kdenetwork/krn/typelayout.cpp:202)
TLObj *KTypeLayout::addButton(const char *ID,const QString &text)
{
QWidget *g;
QPushButton *l=new QPushButton(text,windowStack.top()->widget);
g=l;
g->show();
int w=l->fontMetrics().width(text)+8;
if (w<75) w=75;
g->setFixedWidth(w);
int h=l->fontMetrics().height()+8;
if (h<25) h=25;
g->setFixedHeight(h);
TLObj *o=addWidget(ID,g);
o->align=AlignCenter;
return o;
}
krn'KTypeLayout::addColorButton() (./kdenetwork/krn/typelayout.cpp:223)
TLObj *KTypeLayout::addColorButton(const char *ID,const QColor *c)
{
KColorButton *l;
QWidget *g;
l=new KColorButton(windowStack.top()->widget);
g=l;
g->show();
g->setMinimumHeight(30);
TLObj *o=addWidget(ID,g);
o->align=AlignCenter;
return o;
}
krn'KTypeLayout::addButton() (./kdenetwork/krn/typelayout.cpp:240)
TLObj *KTypeLayout::addButton(const char *ID,const QPixmap &p)
{
QWidget *g;
QPushButton *l=new QPushButton("",windowStack.top()->widget);
l->setPixmap(p);
g=l;
g->show();
int w=p.width()+6;
g->setFixedWidth(w);
int h=p.height()+6;
g->setFixedHeight(h);
TLObj *o=addWidget(ID,g);
o->align=AlignCenter;
return o;
}
krn'KTypeLayout::addCheckBox() (./kdenetwork/krn/typelayout.cpp:259)
TLObj *KTypeLayout::addCheckBox(const char *ID,const char *text,bool value)
{
QWidget *g;
QCheckBox *l=new QCheckBox(text,windowStack.top()->widget);
l->setChecked(value);
g=l;
g->show();
g->setMinimumWidth(l->fontMetrics().width(text)+20);
g->setMinimumHeight(l->fontMetrics().height()>?12);
TLObj *o=addWidget(ID,g);
o->align=AlignLeft|AlignVCenter;
return o;
}
krn'KTypeLayout::addRadioButton() (./kdenetwork/krn/typelayout.cpp:274)
TLObj *KTypeLayout::addRadioButton(const char *ID,const char *GroupID,
const char *text,bool value,int id=-1)
{
QWidget *g;
QRadioButton *l=new QRadioButton(text,windowStack.top()->widget);
QButtonGroup *bg=bgroupDict.find(GroupID);
if (!bg)
{
bg=new QButtonGroup(windowStack.top()->widget,GroupID);
bg->hide();
bgroupDict.insert(GroupID,bg);
}
bg->insert(l,id);
l->setChecked(value);
g=l;
g->show();
g->setMinimumWidth(l->fontMetrics().width(text)+20);
g->setMinimumHeight(l->fontMetrics().height() >? 12);
TLObj *o=addWidget(ID,g);
o->align=AlignLeft|AlignVCenter;
return o;
}
krn'KTypeLayout::addBook() (./kdenetwork/krn/typelayout.cpp:300)
TLBook *KTypeLayout::addBook(const char *ID)
{
QWidget *g;
g=new KTabCtl(windowStack.top()->widget,ID);
g->show();
TLBook *o=new TLBook(ID,g);
o->vslack=g->fontMetrics().height()+8;
o->path=path;
windowStack.top()->layout->rows.last()->append(o);
path=path+ID+".";
windowStack.push(o);
objDict.insert(ID,o);
o->align=AlignCenter;
return o;
}
krn'KTypeLayout::addPage() (./kdenetwork/krn/typelayout.cpp:319)
TLForm *KTypeLayout::addPage(const char *ID,const char *title)
{
QWidget *g;
g=new QFrame(windowStack.top()->widget);
((KTabCtl *)windowStack.top()->widget)->addTab(g,title);
g->show();
TLForm *o=new TLForm(ID,"",g);
o->path=path;
windowStack.top()->layout->rows.last()->append(o);
path=path+ID+".";
windowStack.push(o);
objDict.insert(ID,o);
return o;
}
krn'KTypeLayout::addLineEdit() (./kdenetwork/krn/typelayout.cpp:337)
TLObj *KTypeLayout::addLineEdit(const char *ID,const char *text,int maxlen)
{
QWidget *g;
QLineEdit *l=new QLineEdit(windowStack.top()->widget);
g=l;
if (maxlen>=0)
l->setMaxLength(maxlen);
l->setText(text);
g->show();
g->setFixedHeight(l->fontMetrics().height()+10);
g->setMinimumWidth(l->fontMetrics().width(text)+10);
if (maxlen>0)
g->setMaximumWidth(10+maxlen*l->fontMetrics().maxWidth());
return addWidget(ID,g);
}
krn'KTypeLayout::addIntLineEdit() (./kdenetwork/krn/typelayout.cpp:355)
TLObj *KTypeLayout::addIntLineEdit(const char *ID,const char *text,int maxlen)
{
QWidget *g;
KIntLineEdit *l=new KIntLineEdit(windowStack.top()->widget);
g=l;
if (maxlen>=0)
l->setMaxLength(maxlen);
l->setText(text);
g->show();
g->setFixedHeight(l->fontMetrics().height()+10);
g->setMinimumWidth(l->fontMetrics().width(text)+10);
if (maxlen>0)
g->setMaximumWidth(10+maxlen*l->fontMetrics().width("8"));
return addWidget(ID,g);
}
krn'KTypeLayout::addListBox() (./kdenetwork/krn/typelayout.cpp:373)
TLObj *KTypeLayout::addListBox (const char *ID,QStrList *contents,int minRows)
{
QWidget *g;
QListBox *l=new QListBox(windowStack.top()->widget);
g=l;
if (contents)
l->insertStrList(contents);
g->show();
g->setMinimumHeight((l->fontMetrics().height()+1)*minRows+6);
return addWidget(ID,g);
}
krn'KTypeLayout::addComboBox() (./kdenetwork/krn/typelayout.cpp:386)
TLObj *KTypeLayout::addComboBox (const char *ID,QStrList *contents,bool rw)
{
QWidget *g;
QComboBox *l=new QComboBox(rw,windowStack.top()->widget);
g=l;
int w=0;
if (contents)
{
l->insertStrList(contents);
for (char *item=contents->first();item!=0;item=contents->next())
{
int w2=l->fontMetrics().width(item);
if (w<w2)
w=w2;
}
}
w=w+32;
if (w<75)
w=75;
g->show();
g->setFixedHeight(l->fontMetrics().height()+10);
g->setFixedWidth(w);
return addWidget(ID,g);
}
krn'KTypeLayout::newLine() (./kdenetwork/krn/typelayout.cpp:412)
void KTypeLayout::newLine()
{
KTypeLayout *l=windowStack.top()->layout;
l->rows.append(new QList <TLObj>);
}
krn'KTypeLayout::skip() (./kdenetwork/krn/typelayout.cpp:418)
void KTypeLayout::skip()
{
addLabel("__++__skipspace__++__","");
//Skips shouldn't affect stretching, so ...
setAlign("__++__skipspace__++__",0);
}
krn'KTypeLayout::setAlign() (./kdenetwork/krn/typelayout.cpp:425)
void KTypeLayout::setAlign (char *ID,int align)
{
TLObj *o=findObject(ID);
if (!o)
{
warning ("Aligning unexisting object %s",ID);
return;
}
QWidget *w=o->widget;
if ((align & AlignTop) && (align & AlignBottom))
{
align=align-AlignTop-AlignBottom;
align=align|AlignVCenter;
w->setMaximumHeight(10000);
}
if ((align & AlignLeft) && (align & AlignRight))
{
align=align-AlignLeft-AlignRight;
align=align|AlignHCenter;
w->setMaximumWidth(10000);
}
o->align=align;
}
krn'KTypeLayout::setSpawn() (./kdenetwork/krn/typelayout.cpp:453)
void KTypeLayout::setSpawn (char *ID,int vSpawn,int hSpawn)
{
TLObj *o=findObject(ID);
if (!o)
{
warning ("Setting spawn of unexisting object %s",ID);
return;
}
o->width=vSpawn;
o->height=hSpawn;
}
krn'KTypeLayout::findObject() (./kdenetwork/krn/typelayout.cpp:466)
TLObj *KTypeLayout::findObject(const char *_ID)
{
return objDict.find(_ID);
}
krn'KTypeLayout::findWidget() (./kdenetwork/krn/typelayout.cpp:471)
QWidget *KTypeLayout::findWidget(const char *_ID)
{
TLObj *o=objDict.find(_ID);
if (o)
return o->widget;
return 0;
}