Esempio n. 1
0
void StatusBarLayout::setGeometry( const QRect& _rect )
{
    QLayout::setGeometry( _rect );

    if( mIsDirty )
        updateLayoutStructs();

    QRect rect( 0, 0, _rect.width(), _rect.height() );

    const int margin = 0;//this->margin();
    const int spacing = this->spacing();

    int availableWidth =        rect.size().width()  - 2*margin;
    const int availableHeight = rect.size().height() - 2*margin;

    int usedWidth = 0;
    int visibleCount = 0;
    int i;
    for( i = 0; i<mWidgetList.count(); ++i )
    {
        QWidgetItem* item = mWidgetList.at( i );
        QWidget* widget = item->widget();

        // TODO: is there really no way to get to the geometry data if a widget is hidden?
        if( widget->isHidden() )
            widget->show();

        const int itemWidth = item->sizeHint().width();
        const int itemSpacing = ( visibleCount == 0 ) ? 0 : spacing;
        const int newUsedWidth = usedWidth + itemSpacing + itemWidth;
// kDebug()<<widget<<<<availableWidth<<usedWidth<<itemWidth<<itemSpacing<<newUsedWidth;

        const bool isTooWide = ( newUsedWidth > availableWidth );

        if( isTooWide )
            break;

        const QPoint pos( margin + usedWidth, margin );
        const QSize size( itemWidth, availableHeight );
        QRect r( pos, size );

        r = QStyle::visualRect( parentWidget()->layoutDirection(), rect, r );

        item->setGeometry( r );

        usedWidth = newUsedWidth;

        ++visibleCount;
    }
    // hide the rest if needed
    for( ; i<mWidgetList.count(); ++i )
    {
        QWidgetItem* item = mWidgetList.at( i );
        QWidget* widget = item->widget();

        if( ! widget->isHidden() )
            widget->hide();
    }
}
Esempio n. 2
0
void LayoutDumper::dumpWidgetAndChildren(QDebug& os, const QWidget* w,
                                         int level)
{
    QString padding;
    for (int i = 0; i <= level; i++) {
        padding += "    ";  // 4 spaces per level
    }

    QLayout* layout = w->layout();
    QList<QWidget*> dumped_children;
    if (layout && !layout->isEmpty()) {
        os << padding << "Layout: " << getLayoutInfo(layout);

        QBoxLayout* box_layout = dynamic_cast<QBoxLayout*>(layout);
        if (box_layout) {
            os << ", spacing " <<  box_layout->spacing();
        }
        os << ":\n";

        int num_items = layout->count();
        for (int i = 0; i < num_items; i++) {
            QLayoutItem* layout_item = layout->itemAt(i);
            QString item_info = getLayoutItemInfo(layout_item);
            if (!item_info.isEmpty()) {
                os << padding << "- " << item_info << "\n";
            }

            QWidgetItem* wi = dynamic_cast<QWidgetItem*>(layout_item);
            if (wi && wi->widget()) {
                dumpWidgetAndChildren(os, wi->widget(), level + 1);
                dumped_children.push_back(wi->widget());
            }
        }
    }

    // now output any child widgets that weren't dumped as part of the layout
    QList<QWidget*> widgets = w->findChildren<QWidget*>(
                QString(), Qt::FindDirectChildrenOnly);
    QList<QWidget*> undumped_children;
    foreach (QWidget* child, widgets) {
        if (dumped_children.indexOf(child) == -1) {
            undumped_children.push_back(child);
        }
    }

    if (!undumped_children.empty()) {
        os << padding << "Non-layout children:\n";
        foreach (QWidget* child, undumped_children) {
            dumpWidgetAndChildren(os, child, level + 1);
        }
Esempio n. 3
0
void TaskGroup::actionEvent (QActionEvent* e)
{
    QAction *action = e->action();
    switch (e->type()) {
    case QEvent::ActionAdded:
        {
            TaskIconLabel *label = new TaskIconLabel(
                action->icon(), action->text(), this);
            this->addIconLabel(label);
            connect(label,SIGNAL(clicked()),action,SIGNAL(triggered()));
            break;
        }
    case QEvent::ActionChanged:
        {
            // update label when action changes
            QBoxLayout* bl = this->groupLayout();
            int index = this->actions().indexOf(action);
            if (index < 0) break;
            QWidgetItem* item = static_cast<QWidgetItem*>(bl->itemAt(index));
            TaskIconLabel* label = static_cast<TaskIconLabel*>(item->widget());
            label->setTitle(action->text());
            break;
        }
    case QEvent::ActionRemoved:
        {
            // cannot change anything
            break;
        }
    default:
        break;
    }
}
Esempio n. 4
0
void TreeModel::saveNewData(QWidget *widgetContainer, const QModelIndex &parentIndex)
{
    TreeItem *m_parent = itemFromIndex(parentIndex);

	if (m_parent != NULL)
	{
		int totalChilds = m_parent->childCount();
		QGridLayout *gridLayout = dynamic_cast<QGridLayout*>(widgetContainer->layout());

		for (int i = 0; i < gridLayout->rowCount(); i++)
		{
            QWidgetItem *widgetItem = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,3));
			if (widgetItem)
			{
				QLabel *label = dynamic_cast<QLabel*>(widgetItem->widget());
				QWidgetItem *widgetItem2 = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,1));

				if (label and widgetItem2)
				{
					for (int j = 0; j < totalChilds; j++)
					{
						if (label->text() == m_parent->child(j)->getUID())
						{
							QLineEdit *lineEdit = qobject_cast<QLineEdit*>(widgetItem2->widget());
							QComboBox *comboBox = qobject_cast<QComboBox*>(widgetItem2->widget());
							if (lineEdit)
								m_parent->child(j)->setValue(lineEdit->text());
							else if (comboBox)
                            {
                                QString valAux = "";
                                if (comboBox->currentText() == "TRUE")
                                    valAux = "1";
                                else if (comboBox->currentText() == "FALSE")
                                    valAux = "0";

                                m_parent->child(j)->setValue(valAux);
                            }

							TreeItem *item = new TreeItem(m_parent->child(j));
							m_parent->removeRow(j);
							m_parent->insertRow(j, item);
						}
					}
				}
			}
		}

		emit modelModified();
	}
}
Esempio n. 5
0
QString LayoutDumper::getLayoutItemInfo(QLayoutItem* item)
{
    QWidgetItem* wi = dynamic_cast<QWidgetItem*>(item);
    QSpacerItem* si = dynamic_cast<QSpacerItem*>(item);
    if (wi) {
        if (wi->widget()) {
            return QString("%1 [alignment: %2]")
                    .arg(getWidgetInfo(*wi->widget()))
                    .arg(toString(wi->alignment()));
        }
    } else if (si) {
        QSize hint = si->sizeHint();
        QLayout* layout = si->layout();
        return QString("QSpacerItem: sizeHint (%1 x %2), policy %3, "
                       "constraint %4, alignment %5")
                .arg(hint.width())
                .arg(hint.height())
                .arg(toString(si->sizePolicy()))
                .arg(layout ? toString(layout->sizeConstraint())
                            : "[no layout]")
                .arg(si->alignment());
    }
    return "";
}
Esempio n. 6
0
void ToolBar::changeIconSizeSub(QLayout* layout, const QSize& iconSize)
{
    int n = layout->count();
    for(int i=0; i < n; ++i){
        QLayoutItem* item = layout->itemAt(i);
        QLayout * childLayout = dynamic_cast<QLayout*>(item);
        if(childLayout){
            changeIconSizeSub(childLayout, iconSize);
        }
        QWidgetItem* widgetItem = dynamic_cast<QWidgetItem*>(item);
        if(widgetItem){
            QWidget* widget = widgetItem->widget();
            ToolButton* button = dynamic_cast<ToolButton*>(widget);
            if(button){
                button->setIconSize(mainWindow->iconSize());
            }
        }
    }
}