Beispiel #1
0
void DriverColorsDialog::onResetButtonClicked()
{
    QToolButton *button = static_cast<QToolButton*>(QObject::sender());

    for (int i = 0; i < ui->verticalLayout->count()-2; ++i)
    {
        QHBoxLayout *layout = static_cast<QHBoxLayout*>(ui->verticalLayout->itemAt(i)->layout());
        QToolButton *resetButton = static_cast<QToolButton*>(layout->itemAt(1)->widget());
        QToolButton *colorButton = static_cast<QToolButton*>(layout->itemAt(0)->widget());

        if (button == resetButton)
        {
            setButtonColor(colorButton, ColorsManager::getInstance().getDefaultDriverColors()[i * 2]);
            colors[i * 2] = ColorsManager::getInstance().getDefaultDriverColors()[i * 2];

            return;
        }

        resetButton = static_cast<QToolButton*>(layout->itemAt(4)->widget());
        colorButton = static_cast<QToolButton*>(layout->itemAt(3)->widget());
        if (button == resetButton)
        {
            setButtonColor(colorButton, ColorsManager::getInstance().getDefaultDriverColors()[i * 2 + 1]);
            colors[i * 2 + 1] = ColorsManager::getInstance().getDefaultDriverColors()[i * 2 + 1];

            return;
        }
    }
}
Beispiel #2
0
 void fixTabOrder() {
     QWidget *cur = NULL;
     if (hLayout->count() > 0)
         p->setTabOrder(p, (cur = hLayout->itemAt(0)->widget()));
     for (int i = 1; i < hLayout->count(); ++i) {
         QWidget *next = hLayout->itemAt(i)->widget();
         p->setTabOrder(cur, next);
         cur = next;
     }
 }
Beispiel #3
0
void koregui::FrameBufferEditor::applySettings(void) {
    if(!_currentbuffer) return;
    uint colortarget = 0;
    for(int i = 0; i < ui.tableWidget->rowCount(); i++) {
        kore::STextureProperties props;
        props.targetType = GL_TEXTURE_2D;

        QHBoxLayout* hlay =
            static_cast<QHBoxLayout*>(ui.tableWidget->cellWidget(i, 1)->layout());
        QLineEdit* res = static_cast<QLineEdit*>(hlay->itemAt(0)->widget());
        uint resx = res->text().toUInt();
        res = static_cast<QLineEdit*>(hlay->itemAt(2)->widget());
        uint resy = res->text().toUInt();
        QCheckBox* cb = static_cast<QCheckBox*>(hlay->itemAt(3)->widget());
        bool autores = (cb->isChecked())?true:false;

        props.width = resx;
        props.height = resy;

        QComboBox* cbox =
            static_cast<QComboBox*>(ui.tableWidget->cellWidget(i, 2));
        props.format = cbox->itemData(cbox->currentIndex()).toUInt();
        cbox = static_cast<QComboBox*>(ui.tableWidget->cellWidget(i, 3));
        props.internalFormat = cbox->itemData(cbox->currentIndex()).toUInt();
        cbox = static_cast<QComboBox*>(ui.tableWidget->cellWidget(i, 4));
        props.pixelType = cbox->itemData(cbox->currentIndex()).toUInt();

        cbox = static_cast<QComboBox*>(ui.tableWidget->cellWidget(i, 0));
        GLuint target = cbox->itemData(cbox->currentIndex()).toUInt();

        switch(target) {
        case GL_COLOR_ATTACHMENT0:
            _currentbuffer->addTextureAttachment(props,
                                                 "Color",
                                                 GL_COLOR_ATTACHMENT0 + colortarget);
            colortarget++;
            break;
        case GL_DEPTH_ATTACHMENT:
            _currentbuffer->addTextureAttachment(props,
                                                 "Depth",
                                                 GL_DEPTH_ATTACHMENT);
            break;
        case GL_STENCIL_ATTACHMENT:
            _currentbuffer->addTextureAttachment(props,
                                                 "Stencil",
                                                 GL_STENCIL_ATTACHMENT);
            break;
        default:
            // ERROR
            break;
        }
    }
    _currentitem->setFrameBuffer(_currentbuffer);
    refresh();
}
Beispiel #4
0
 void setReadOnly(bool isReadOnly) {
     m_isReadOnly = isReadOnly;
     for (int i = hLayout->count() - 1; i >= 0; --i) {
         QWidget *w = hLayout->itemAt(i)->widget();
         setWidgetReadOnly(w, isReadOnly);
     }
 }
Beispiel #5
0
void tst_QBoxLayout::testLayoutEngine()
{
    QFETCH(DescrList, itemDescriptions);
    QFETCH(int, size);
    QFETCH(int, spacing);
    QFETCH(PosList, expectedPositions);
    QFETCH(SizeList, expectedSizes);

    QHBoxLayout box;
    box.setSpacing(spacing);
    int i;
    for (i = 0; i < itemDescriptions.count(); ++i) {
         Descr descr = itemDescriptions.at(i);
         LayoutItem *li = new LayoutItem(descr);
         box.addItem(li);
         box.setStretch(i, descr.stretch);
    }
    box.setGeometry(QRect(0,0,size,100));
    for (i = 0; i < expectedSizes.count(); ++i) {
        int xSize = expectedSizes.at(i);
        int xPos = expectedPositions.at(i);
        QLayoutItem *item = box.itemAt(i);
        QCOMPARE(item->geometry().width(), xSize);
        QCOMPARE(item->geometry().x(), xPos);
    }
}
Beispiel #6
0
void DriverColorsDialog::on_pushButton_clicked()
{
    for (int i = 0; i < ui->verticalLayout->count()-2; ++i)
    {
        QHBoxLayout *layout = static_cast<QHBoxLayout*>(ui->verticalLayout->itemAt(i)->layout());
        QToolButton *colorButton = static_cast<QToolButton*>(layout->itemAt(0)->widget());

        setButtonColor(colorButton, ColorsManager::getInstance().getDefaultDriverColors()[i * 2]);
        colors[i * 2] = ColorsManager::getInstance().getDefaultDriverColors()[i * 2];

        colorButton = static_cast<QToolButton*>(layout->itemAt(3)->widget());

        setButtonColor(colorButton, ColorsManager::getInstance().getDefaultDriverColors()[i * 2 + 1]);
        colors[i * 2 + 1] = ColorsManager::getInstance().getDefaultDriverColors()[i * 2 + 1];
    }
}
Beispiel #7
0
 void setStyleSheet(bool makeInnerWidgetsTransparent) {
     this->makeInnerWidgetsTransparent = makeInnerWidgetsTransparent;
     for (int i = hLayout->count() - 1; i >= 0; --i) {
         QWidget *w = hLayout->itemAt(i)->widget();
         if (w != NULL)
             w->setStyleSheet(makeInnerWidgetsTransparent ? transparentStyleSheet : normalStyleSheet);
     }
 }
    void updateItemWidgets(const QList<QWidget*> widgets,
                           const QStyleOptionViewItem &option,
                           const QPersistentModelIndex &index) const
    {
        FileItem *fileItem = (FileItem*)index.data().value<void*>();

        QWidget* page= widgets[0];
        QHBoxLayout* layout = qobject_cast<QHBoxLayout*>(page->layout());
        QCheckBox *checkBox = qobject_cast<QCheckBox*>(layout->itemAt(0)->widget());
        QLabel *thumbnail = qobject_cast<QLabel*>(layout->itemAt(1)->widget());
        QLabel *filename = qobject_cast<QLabel*>(layout->itemAt(2)->widget());
        QLabel *modified = qobject_cast<QLabel*>(layout->itemAt(3)->widget());

        checkBox->setChecked(fileItem->checked);
        thumbnail->setPixmap(QPixmap::fromImage(fileItem->thumbnail));
        filename->setText(fileItem->name);
        modified->setText(fileItem->date);

        // move the page _up_ otherwise it will draw relative to the actual postion
        page->setGeometry(option.rect.translated(0, -option.rect.y()));
    }
Beispiel #9
0
ActionLineEditButton * ActionLineEdit::widgetForAction ( QAction * action )
{
	QHBoxLayout *lo = (QHBoxLayout *)layout();
	ActionLineEditButton *btn;
	for (int i=1, count=lo->count(); i<count; i++) {
		btn = (ActionLineEditButton *)lo->itemAt(i)->widget();
		if (btn->defaultAction() == action) {
			return btn;
		}
	}
	return 0;
}
Beispiel #10
0
void ActionLineEdit::actionEvent ( QActionEvent * event )
{
	QHBoxLayout *lo = (QHBoxLayout *)layout();
	QAction *act = event->action();
	ActionLineEditButton *btn;
	if (event->type() == QEvent::ActionAdded) {
		btn = new ActionLineEditButton(this);
		QAction *before = event->before();
		int beforeInd;
		if (before && (beforeInd = actions().indexOf(before)) >= 0) { //TODO test it
			lo->insertWidget(beforeInd + 1, btn); //1 - first item is spacer. skip it
		}
		else {
			lo->addWidget(btn);
		}
		btn->setDefaultAction(act);
	}
	else if (event->type() == QEvent::ActionRemoved) {
		for (int i=1, count=lo->count(); i<count; i++) {
			btn = (ActionLineEditButton *)lo->itemAt(i)->widget();
			if (btn->defaultAction() == act) {
				lo->removeWidget(btn);
				delete btn;
				break;
			}
		}
	}
	int sumWidth = 0;
	for (int i=1, count=lo->count(); i<count; i++) {
		btn = (ActionLineEditButton *)lo->itemAt(i)->widget();
		if (btn->defaultAction()->isVisible()) {
			sumWidth += btn->width();
		}
	}
	sumWidth += 4; //+4px padding between text and buttons. should looks better (magic number)
	int mLeft, mTop, mRight, mBottom;
	getTextMargins(&mLeft, &mTop, &mRight, &mBottom);
	setTextMargins(mLeft, mTop, sumWidth, mBottom);
}
Beispiel #11
0
    void verticallyStretchButtons() {
        /// do not vertically stretch if using transparent style sheet
        if (makeInnerWidgetsTransparent) return;

        /// check each widget inside MenuLineEdit
        for (int i = hLayout->count() - 1; i >= 0; --i) {
            QWidget *w = hLayout->itemAt(i)->widget();
            if (w != NULL && w != m_singleLineEditText && w != m_multiLineEditText) {
                /// for all widgets except the main editing widget: change tab focus policy
                QSizePolicy sp = w->sizePolicy();
                w->setSizePolicy(sp.horizontalPolicy(), QSizePolicy::MinimumExpanding);
            }
        }
    }
Beispiel #12
0
void DriverColorsDialog::onColorButtonClicked()
{
    QToolButton *button = static_cast<QToolButton*>(QObject::sender());

    for (int i = 0; i < ui->verticalLayout->count()-2; ++i)
    {
        QHBoxLayout *layout = static_cast<QHBoxLayout*>(ui->verticalLayout->itemAt(i)->layout());
        QToolButton *colorButton = static_cast<QToolButton*>(layout->itemAt(0)->widget());

        if (button == colorButton)
        {
            QColor color = QColorDialog::getColor(colors[i * 2], this);

            if (color.isValid())
            {
                setButtonColor(colorButton, color);
                colors[i * 2] = color;
            }

            return;
        }

        colorButton = static_cast<QToolButton*>(layout->itemAt(3)->widget());
        if (button == colorButton)
        {
            QColor color = QColorDialog::getColor(colors[i * 2 + 1], this);

            if (color.isValid())
            {
                setButtonColor(colorButton, color);
                colors[i * 2 + 1] = color;
            }

            return;
        }
    }
}
QWidget * find_widget(const GraphicalUri* value, int index)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalUri

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QWidget * widget = nullptr;

  if( is_not_null(layout) )
    widget = layout->itemAt(index)->widget();
  else
    std::cerr << "Failed to find the layout or cast it to QHBoxLayout." << std::endl;

  return widget;
}
Beispiel #14
0
void MediaBrowser::indexSingleClicked(const QModelIndex &idx)
{
	QFileInfo info = m_fsModel->fileInfo(idx);
	m_btnBase->setEnabled(idx.isValid() && !info.isDir());

	m_viewer->setStartBackgroundVideoPausedInPreview(!m_autoPlayVideo);
	if(SlideGroup::canUseBackground(info))
		m_viewer->slideGroup()->changeBackground(info);
	else
		m_viewer->slideGroup()->changeBackground(AbstractVisualItem::Solid,"#000");
		
	if(m_controlWidget)
	{
		m_viewerLayout->removeWidget(m_controlWidget);
		delete m_controlWidget; //->deleteLater();
		m_controlWidget = 0;
	}
	
	if(MediaBrowser::isVideo(info.suffix()))
	{
		QList<QWidget*> widgets = m_viewer->controlWidgets();
		if(!widgets.isEmpty())
		{
			m_controlWidget = widgets.takeFirst();
			
			
			m_autoPlayCheckbox = new QCheckBox(m_controlWidget);
			m_autoPlayCheckbox->setChecked(m_autoPlayVideo);
			
			QLabel *label = new QLabel("Auto-play",m_controlWidget);
			label->setBuddy(m_autoPlayCheckbox);
			connect(m_autoPlayCheckbox, SIGNAL(toggled(bool)), this, SLOT(setAutoPlayVideo(bool)));
			
			
			QHBoxLayout *layout = dynamic_cast<QHBoxLayout*>(m_controlWidget->layout());
			if(layout)
			{
				//m_controlWidget->setStyleSheet("QLabel{display:none}"
				layout->itemAt(0)->widget()->setVisible(false);
				layout->addStretch(1);
				layout->addWidget(m_autoPlayCheckbox);
				layout->addWidget(label);
			}
			
			m_controlWidget->setParent(m_viewerBase);
			m_viewerLayout->addWidget(m_controlWidget);
		}
Beispiel #15
0
    virtual void notificationEvent(int eventId) {
        if (eventId == MenuLineEdit::MenuLineConfigurationChangedEvent) {
            /// load setting limitKeyboardTabStops
            KSharedConfigPtr config(KSharedConfig::openConfig(QStringLiteral("kbibtexrc")));
            static QString const configGroupName = QStringLiteral("User Interface");
            KConfigGroup configGroup(config, configGroupName);
            const bool limitKeyboardTabStops = configGroup.readEntry(MenuLineEdit::keyLimitKeyboardTabStops, false);

            /// check each widget inside MenuLineEdit
            for (int i = hLayout->count() - 1; i >= 0; --i) {
                QWidget *w = hLayout->itemAt(i)->widget();
                if (w != NULL && w != m_singleLineEditText && w != m_multiLineEditText) {
                    /// for all widgets except the main editing widget: change tab focus policy
                    w->setFocusPolicy(limitKeyboardTabStops ? Qt::ClickFocus : Qt::StrongFocus);
                }
            }
        }
    }
Beispiel #16
0
QCheckBox * GraphicalBoolTest::findCheckBox(const GraphicalBool* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalBool

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QCheckBox * checkBox = nullptr;

  if( is_not_null(layout) )
  {
    checkBox = dynamic_cast<QCheckBox*>(layout->itemAt(0)->widget());

    if( is_null(checkBox) )
      QWARN("Failed to find the check box.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return checkBox;
}
QLineEdit * GraphicalDoubleTest::findLineEdit(const GraphicalDouble* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalDouble

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QLineEdit * lineEdit = nullptr;

  if( is_not_null(layout) )
  {
    lineEdit = dynamic_cast<QLineEdit*>(layout->itemAt(0)->widget());

    if( is_null(lineEdit) )
      QWARN("Failed to find the line edit.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return lineEdit;
}
Beispiel #18
0
QDoubleSpinBox * GraphicalIntTest::findSpinBox(const GraphicalInt* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalInt

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QDoubleSpinBox * spinBox = nullptr;

  if( is_not_null(layout) )
  {
    spinBox = dynamic_cast<QDoubleSpinBox*>(layout->itemAt(0)->widget());

    if( is_null(spinBox) )
      QWARN("Failed to find the spin box.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return spinBox;
}
Beispiel #19
0
 ~MenuLineEditPrivate() {
     for (int i = hLayout->count() - 1; i >= 0; --i) {
         QWidget *w = hLayout->itemAt(i)->widget();
         w->deleteLater();
     }
 }
LayoutAliasEditDialog::LayoutAliasEditDialog(NineMLLayout * inSrcNineMLLayout, QWidget *parent) :
    QDialog(parent)
{

    srcNineMLLayout = inSrcNineMLLayout;

    this->setModal(true);
    this->setMinimumSize(450, 400);
    this->setWindowTitle("Edit Aliases");
    //this->setWindowIcon();

    // width of the delete box:
    int delWidth = 30;

    // add the main layout
    this->setLayout(new QVBoxLayout);
    this->layout()->setContentsMargins(0,0,0,0);

    // make the dialog scrollable
    this->layout()->addWidget(new QScrollArea);
    QWidget * content = new QWidget;
    ((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidget(content);
    ((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidgetResizable(true);
    content->setLayout(new QVBoxLayout);
    QVBoxLayout * contentLayout = (QVBoxLayout *) content->layout();

    // start adding the items, header first:
    QHBoxLayout * header = new QHBoxLayout;
    header->addWidget(new QLabel("<b>Name</b>"), 1);
    header->addWidget(new QLabel("<b>Maths</b>"),3);
    header->addWidget(new QLabel(""));
    header->itemAt(2)->widget()->setFixedWidth(delWidth);
    contentLayout->addLayout(header);

    // add the aliases
    for (uint i = 0; i < srcNineMLLayout->AliasList.size(); ++i) {

        // add to main layout
        contentLayout->addLayout(drawAlias(srcNineMLLayout->AliasList[i]));

    }

    QFont addFont("Helvetica [Cronyx]", 8);

    // add new alias button
    QPushButton * addAlias = new QPushButton("Alias");
    addAlias->setIcon(QIcon(":/icons/toolbar/addShad.png"));
    addAlias->setMaximumWidth(110);
    addAlias->setFlat(true);
    addAlias->setFocusPolicy(Qt::NoFocus);
    addAlias->setToolTip("Add a new Alias");
    addAlias->setFont(addFont);
    addAlias->setProperty("layout", qVariantFromValue((void *) contentLayout));
    QObject::connect(addAlias, SIGNAL(clicked()), this, SLOT(addAlias()));
    contentLayout->addWidget(addAlias);

    // make sure it all goes to the top of the dialog
    contentLayout->addStretch();

    QHBoxLayout * exitLayout = new QHBoxLayout;
    exitLayout->addStretch();
    QPushButton * exit = new QPushButton("Finished");
    exit->setMaximumWidth(100);
    QObject::connect(exit, SIGNAL(clicked()), this, SLOT(close()));
    exitLayout->addWidget(exit);
    contentLayout->addLayout(exitLayout);

}
Beispiel #21
0
 void setEnabledLayout(bool enabled) {
    for (int i = 0; i < groupLayout.count(); i++)
       if (auto widget = groupLayout.itemAt(i)->widget())
          widget->setEnabled(enabled);
 }
void GameWidgetScrollArea::resizeEvent(QResizeEvent * event) {
	int widgetWidth = GameChoiceWidget::getWidgetWidth();
	int widgetsPerRowNew = event->size().width() / widgetWidth;

	if (widgetsPerRowNew <= 0) {
		fprintf(stderr, "Error: window too small. Exiting.\n");
		static GameController* instance = GameController::acquire();
		instance->terminateApplication();
	}

	if (widgetsPerRowNew < m_widgetsPerRow) {
		// too many widgets per row, must make rows shorter

		QVBoxLayout* overallLayout = (QVBoxLayout*) this->widget()->layout();

		int numToMove = m_widgetsPerRow - widgetsPerRowNew;
		for (int i = 0; i < overallLayout->count() - 1 && numToMove > 0; ++i) {
			QHBoxLayout* horizontalRow =
					(QHBoxLayout*) overallLayout->itemAt(i)->layout();
			QHBoxLayout* nextHorizontalRow;
			for (int j = 0; j < numToMove; ++j) {
				QWidget* lastWidget = horizontalRow->itemAt(
						horizontalRow->count() - 2)->widget();
				horizontalRow->removeWidget(lastWidget);

				if (i == overallLayout->count() - 2) {
					QHBoxLayout* newRow = new QHBoxLayout();
					newRow->addStretch(ms_stretchFactor);
					overallLayout->insertLayout(overallLayout->count() - 1,
							newRow);
				}

				nextHorizontalRow =
						(QHBoxLayout*) overallLayout->itemAt(i + 1)->layout();
				nextHorizontalRow->insertWidget(0, lastWidget, 0,
						Qt::AlignLeading);
			}

			numToMove = nextHorizontalRow->count() - widgetsPerRowNew - 1;
		}

		m_widgetsPerRow = std::min(widgetsPerRowNew, m_totalNumberGameWidgets);
	} else if (m_widgetsPerRow < m_totalNumberGameWidgets
			&& widgetsPerRowNew > m_widgetsPerRow) {
		// add widgets to each row to make each longer and have less rows

		QVBoxLayout* overallLayout = (QVBoxLayout*) this->widget()->layout();

		int numToMove = widgetsPerRowNew - m_widgetsPerRow;

		QHBoxLayout* currentHorizontalRow =
				(QHBoxLayout*) overallLayout->itemAt(0)->layout();
		for (int i = 1; i < overallLayout->count() - 1; ++i) {
			QHBoxLayout* nextHorizontalRow =
					(QHBoxLayout*) overallLayout->itemAt(i)->layout();

			for (int j = 0; j < numToMove; ++j) {
				if (nextHorizontalRow->count() <= 1) {
					if (i == overallLayout->count() - 2) {
						overallLayout->removeItem(overallLayout->itemAt(i));
						break;
					}
					overallLayout->removeItem(overallLayout->itemAt(i));
					nextHorizontalRow =
							(QHBoxLayout*) overallLayout->itemAt(i)->layout();
				}
				QWidget* firstWidget = nextHorizontalRow->itemAt(0)->widget();
				nextHorizontalRow->removeWidget(firstWidget);
				currentHorizontalRow->insertWidget(
						currentHorizontalRow->count() - 1, firstWidget);
			}

			currentHorizontalRow = nextHorizontalRow;

			numToMove = widgetsPerRowNew - (nextHorizontalRow->count() - 1);
		}

		m_widgetsPerRow = std::min(widgetsPerRowNew, m_totalNumberGameWidgets);
	}

	QWidget* content = this->widget();
	content->resize(this->width(), content->sizeHint().height());
}
Beispiel #23
0
int DriverColorsDialog::exec()
{
    SeasonData &sd = SeasonData::getInstance();
    colors = ColorsManager::getInstance().getDriverColors();
    int i = 0;
    for (; i < sd.getTeams().size(); ++i)
    {
        QList<LTDriver> drivers = sd.getMainDrivers(sd.getTeams()[i]);
        if (drivers.size() != 2)
            continue;

        if ((ui->verticalLayout->count()-2) <= i)
        {
            QHBoxLayout *layout = new QHBoxLayout();
            QLabel *label = new QLabel(this);                        

            label->setText(QString("%1 %2").arg(drivers[0].no).arg(drivers[0].name));
            label->updateGeometry();
            QToolButton *button = new QToolButton(this);
            button->setMaximumHeight(16);
            button->setMaximumWidth(16);
            setButtonColor(button, /*sd.getCarColor(sd.getTeams()[i].driver1No)*/colors[i*2]);
            layout->addWidget(button);
            connect(button, SIGNAL(clicked()), this, SLOT(onColorButtonClicked()));

            button = new QToolButton(this);
            button->setText("Reset");
            button->setMaximumHeight(20);
            layout->addWidget(button);
            connect(button, SIGNAL(clicked()), this, SLOT(onResetButtonClicked()));

            layout->addWidget(label);
            //colors.append(sd.getCarColor(sd.getTeams()[i].driver1No));

//            layout = new QHBoxLayout(this);
            label = new QLabel(this);
            label->setText(QString("%1 %2").arg(drivers[1].no).arg(drivers[1].name));
            label->updateGeometry();
            button = new QToolButton(this);
            button->setMaximumHeight(16);
            button->setMaximumWidth(16);
            setButtonColor(button, /*sd.getCarColor(sd.getTeams()[i].driver2No)*/colors[i*2+1]);
            layout->addWidget(button);
            connect(button, SIGNAL(clicked()), this, SLOT(onColorButtonClicked()));

            button = new QToolButton(this);
            button->setText("Reset");
            button->setMaximumHeight(20);
            layout->addWidget(button);
            connect(button, SIGNAL(clicked()), this, SLOT(onResetButtonClicked()));

            layout->addWidget(label);
            //colors.append(sd.getCarColor(sd.getTeams()[i].driver2No));

            ui->verticalLayout->insertLayout(ui->verticalLayout->count() - 2, layout);
        }
        else
        {
            QHBoxLayout *layout = static_cast<QHBoxLayout*>(ui->verticalLayout->itemAt(i)->layout());
            QLabel *label = static_cast<QLabel*>(layout->itemAt(2)->widget());
            QToolButton *button = static_cast<QToolButton*>(layout->itemAt(0)->widget());

            label->setText(QString("%1 %2").arg(drivers[0].no).arg(drivers[0].name));
            setButtonColor(button, ColorsManager::getInstance().getCarColor(drivers[0].no));

            label->setVisible(true);
            button->setVisible(true);

            button = static_cast<QToolButton*>(layout->itemAt(1)->widget());
            button->setVisible(true);

            label = static_cast<QLabel*>(layout->itemAt(5)->widget());
            button = static_cast<QToolButton*>(layout->itemAt(3)->widget());

            label->setText(QString("%1 %2").arg(drivers[1].no).arg(drivers[1].name));
            setButtonColor(button, ColorsManager::getInstance().getCarColor(drivers[1].no));

            label->setVisible(true);
            button->setVisible(true);

            button = static_cast<QToolButton*>(layout->itemAt(4)->widget());
            button->setVisible(true);
        }
    }
    for (; i < ui->verticalLayout->count()-2; ++i)
    {
        QHBoxLayout *layout = static_cast<QHBoxLayout*>(ui->verticalLayout->itemAt(i)->layout());
        QLabel *label = static_cast<QLabel*>(layout->itemAt(2)->widget());
        QToolButton *button = static_cast<QToolButton*>(layout->itemAt(0)->widget());

        label->setVisible(false);
        button->setVisible(false);

        button = static_cast<QToolButton*>(layout->itemAt(1)->widget());
        button->setVisible(false);

        label = static_cast<QLabel*>(layout->itemAt(5)->widget());
        button = static_cast<QToolButton*>(layout->itemAt(3)->widget());

        label->setVisible(false);
        button->setVisible(false);

        button = static_cast<QToolButton*>(layout->itemAt(4)->widget());
        button->setVisible(false);
    }

    return QDialog::exec();
}
void CTimelineWidget::UpdateTimeline()
{
    QLayoutItem *child;
    if(layout() != Q_NULLPTR)
    {
        while (((child = layout()->takeAt(0)) != 0)) {
            //                                    delete child->widget();
            delete child;
        }
        delete layout();
    }   
    m_pLoader->start();
    QHBoxLayout* pHBLayout = new QHBoxLayout(this);
    pHBLayout->setSpacing(6);
    pHBLayout->setContentsMargins(3, 3, 3, 3);
    QPalette Pal(palette());
    Pal.setColor(QPalette::Background, QColor(240,240,240));
    setAutoFillBackground(true);
    setPalette(Pal);

    int iLayout1 = 0;
    int iLayout2 = 0;
    QList<int> lPendingGames = QList<int>();
    for (int i = 0; i < m_pThumbnailList->length(); i++)
    {
        if (m_pThumbnailList->at(i)->GetSyncedID() != QString("")) {
            int j = FindThumbnailIndex(m_pThumbnailList->at(i)->GetSyncedID());
            if (j >= 0) {
                if (i < j)
                {
                    pHBLayout->addWidget(NewColumn(true));
                    AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(pHBLayout->count()-1)->widget());
                    AddThumbnail(m_pThumbnailList->at(j), pHBLayout->itemAt(pHBLayout->count()-1)->widget());
                    if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_1)
                    {
                        iLayout1 = pHBLayout->count();
                        lPendingGames.append(iLayout1);
                    }
                    else if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_2)
                    {
                        iLayout2 = pHBLayout->count();
                        lPendingGames.append(iLayout2);
                    }
                }
                else
                {
                    if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_1)
                    {
                        iLayout1 = lPendingGames.takeFirst();
                    }
                    else if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_2)
                    {
                        iLayout2 = lPendingGames.takeFirst();
                    }
                }
            }
        }
        else if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_1)
        {
            if (iLayout1 >= pHBLayout->count())
            {
                pHBLayout->addWidget(NewColumn(false));

            }
            if (!AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(iLayout1)->widget()))
            {
                pHBLayout->insertWidget(iLayout1, NewColumn(false));
                AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(iLayout1)->widget());
                iLayout2++;
                for (QList<int>::Iterator g = lPendingGames.begin(); g != lPendingGames.end(); g++) {
                    (*g)++;
                }
            }
            iLayout1++;
        }
        else if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::PLAYER_2)
        {
            if (iLayout2 >= pHBLayout->count())
            {
                pHBLayout->addWidget(NewColumn(false));
            }
            if (!AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(iLayout2)->widget()))
            {
                pHBLayout->insertWidget(iLayout2, NewColumn(false));
                AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(iLayout2)->widget());
                iLayout1++;
                for (QList<int>::Iterator g = lPendingGames.begin(); g != lPendingGames.end(); g++) {
                    (*g)++;
                }
            }
            iLayout2++;
        }
        else if (m_pThumbnailList->at(i)->GetPlayerID() == CMainWindow::BOTH_PLAYER)
        {
            pHBLayout->addWidget(NewColumn(false));
            AddThumbnail(m_pThumbnailList->at(i), pHBLayout->itemAt(pHBLayout->count()-1)->widget());
            iLayout1 = pHBLayout->count();
            iLayout2 = pHBLayout->count();
        }
    }

    setLayout(pHBLayout);
}