Example #1
0
void StartMenu::SortScrollArea(QScrollArea *area){
  //qDebug() << "Sorting Scroll Area:";
  //Sort all the items in the scroll area alphabetically
  QLayout *lay = area->widget()->layout();
  QStringList items;
  for(int i=0; i<lay->count(); i++){
    items << lay->itemAt(i)->widget()->whatsThis();
  }
  
  items.sort();
  //qDebug() << " - Sorted Items:" << items;
  for(int i=0; i<items.length(); i++){
    if(items[i].isEmpty()){ continue; }
    //QLayouts are weird in that they can only add items to the end - need to re-insert almost every item
    for(int j=0; j<lay->count(); j++){
      //Find this item
      if(lay->itemAt(j)->widget()->whatsThis()==items[i]){
	//Found it - now move it if necessary
	//qDebug() << "Found Item:" << items[i] << i << j;
	lay->addItem( lay->takeAt(j) );
	break;
      }
    }
  }
}
void TestController::unload() {
    //Inputs
    QLayout* layout = getView().getUi().grx_test_inputs->layout();

    for (int i = layout->count() - 1; i >= 0; --i) {
        QLayoutItem* item = layout->itemAt(i);
        GuiGrapher* g = dynamic_cast<GuiGrapher*> (item->widget());
        if (g) {
            QObject::disconnect(g, SIGNAL(onChangeInputValue()), this,
                                SLOT(onInputValueChanged()));
        }
        layout->removeItem(item);
        delete item->widget();
        delete item;
    }

    //Rules
    getView().getUi().lsw_test_rules->clear();
    getView().getUi().lsw_test_rules_activation->clear();

    //Outputs
    layout = getView().getUi().grx_test_outputs->layout();
    for (int i = layout->count() - 1; i >= 0; --i) {
        QLayoutItem* item = layout->itemAt(i);
        GuiGrapher* g = dynamic_cast<GuiGrapher*> (item->widget());
        if (g) {
            QObject::disconnect(this, SIGNAL(forceUpdate()), g, SLOT(updateUi()));
        }
        layout->removeItem(item);
        delete item->widget();
        delete item;
    }
}
Example #3
0
bool CategoryWidget::cycleContacts(FriendWidget* activeChatroomWidget, bool forward)
{
    int index = -1;
    QLayout* currentLayout = nullptr;

    FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
    if (friendWidget == nullptr)
        return false;

    currentLayout = listLayout->getLayoutOnline();
    index = listLayout->indexOfFriendWidget(friendWidget, true);
    if (index == -1)
    {
        currentLayout = listLayout->getLayoutOffline();
        index = listLayout->indexOfFriendWidget(friendWidget, false);
    }

    index += forward ? 1 : -1;
    for (;;)
    {
        // Bounds checking.
        if (index < 0)
        {
            if (currentLayout == listLayout->getLayoutOffline())
                currentLayout = listLayout->getLayoutOnline();
            else
                return false;

            index = currentLayout->count() - 1;
            continue;
        }
        else if (index >= currentLayout->count())
        {
            if (currentLayout == listLayout->getLayoutOnline())
                currentLayout = listLayout->getLayoutOffline();
            else
                return false;

            index = 0;
            continue;
        }

        GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
        if (chatWidget != nullptr)
            emit chatWidget->chatroomWidgetClicked(chatWidget);
        return true;
    }

    return false;
}
Example #4
0
void GPhidgetManagerWidget::UpdateSubDevicesWidgetList()
{
	GPhidgetManager* pPhidMan = qobject_cast<GPhidgetManager*>(Device());
	QLayout *pLayout = layout();
	if(!pPhidMan || !pLayout)
		return;
	QList<GDevice*> oldList = m_ListDev;
	m_ListDev = pPhidMan->m_SerialPhidgetModules.values();
	// make a list of new items in the m_ListDev
	QList<GDevice*> newDevicesInList = m_ListDev;
	foreach(GDevice* pDev, m_ListDev)
		if(oldList.contains(pDev))
			newDevicesInList.removeOne(pDev);
	// make a list of items that are gone from the m_ListDev
	QList<GDevice*> goneDevicesInList = oldList;
	foreach(GDevice* pDev, oldList)
		if(m_ListDev.contains(pDev))
			goneDevicesInList.removeOne(pDev);

	// lets delete the gone's and create the new's
	foreach(GDevice* pDev, goneDevicesInList) {
		for (int i = 0; i < pLayout->count(); ++i) {
			GDeviceWidget* pWid = qobject_cast<GDeviceWidget*>(pLayout->itemAt(i)->widget());
			if(pWid && goneDevicesInList.contains(pWid->Device())) {
				pLayout->removeWidget(pWid);
				delete pWid;
			}
		}
	}
	foreach(GDevice* pDev, newDevicesInList) {
		GDeviceWidget* subDevWidget = pDev->ProvideNewDeviceGroupBox(this);
		pLayout->addWidget(subDevWidget);
	}
Example #5
0
void MainWindow::addSpinBoxes(bool checked, int count, Range range)
{
    if (checked) {
        QWidget *w = new QWidget(ui->quantifierValuesGroupBox);
        if (ui->quantifierValuesGroupBox->layout() == 0) {
            QHBoxLayout *hbl = new QHBoxLayout(ui->quantifierValuesGroupBox);
            ui->quantifierValuesGroupBox->setLayout(hbl);
        }
        ui->quantifierValuesGroupBox->layout()->addWidget(w);
        QFormLayout *fl = new QFormLayout(w);
        for (int i = 0; i < count; i++) {
            QAbstractSpinBox *asb;
            if (range == Absolute) {
                QSpinBox *sb = new QSpinBox(w);
                sb->setMinimum(0);
                sb->setMaximum(10000);
                asb = sb;
            } else {
                QDoubleSpinBox *sb = new QDoubleSpinBox(w);
                sb->setMinimum(0);
                sb->setMaximum(1);
                sb->setSingleStep(0.05);
                asb = sb;
            }
            fl->addRow(QString(QChar('A' + i)), asb);
        }
    } else {
        QLayout *fl = ui->quantifierValuesGroupBox->layout();
        if (fl != nullptr && fl->count() > 0) {
            QWidget *w = fl->takeAt(0)->widget();
            delete w;
            // there is no mem-leak here, qt handles qobject's children by itself
        }
    }
}
Example #6
0
// Writes the user input from the form into the oc_auth_form structs we got from
// libopenconnect, and wakes the worker thread up to try to log in and obtain a
// cookie with this data
void OpenconnectAuthWidget::formLoginClicked()
{
    Q_D(OpenconnectAuthWidget);

    const int lastIndex = d->ui.loginBoxLayout->count() - 1;
    QLayout *layout = d->ui.loginBoxLayout->itemAt(d->passwordFormIndex)->layout();
    struct oc_auth_form *form = (struct oc_auth_form *) d->ui.loginBoxLayout->itemAt(lastIndex)->widget()->property("openconnect_form").value<quintptr>();

    for (int i = 0; i < layout->count(); i++) {
        QLayoutItem *item = layout->itemAt(i);
        QWidget *widget = item->widget();
        if (widget && widget->property("openconnect_opt").isValid()) {
            struct oc_form_opt *opt = (struct oc_form_opt *) widget->property("openconnect_opt").value<quintptr>();
            const QString key = QString("form:%1:%2").arg(QLatin1String(form->auth_id)).arg(QLatin1String(opt->name));
            if (opt->type == OC_FORM_OPT_PASSWORD || opt->type == OC_FORM_OPT_TEXT) {
                QLineEdit *le = qobject_cast<QLineEdit*>(widget);
                QByteArray text = le->text().toUtf8();
                openconnect_set_option_value(opt, text.data());
                if (opt->type == OC_FORM_OPT_TEXT) {
                    d->secrets.insert(key, le->text());
                } else {
                    d->tmpSecrets.insert(key, le->text());
                }
            } else if (opt->type == OC_FORM_OPT_SELECT) {
                QComboBox *cbo = qobject_cast<QComboBox*>(widget);
                QByteArray text = cbo->itemData(cbo->currentIndex()).toString().toAscii();
                openconnect_set_option_value(opt, text.data());
                d->secrets.insert(key,cbo->itemData(cbo->currentIndex()).toString());
            }
        }
    }

    deleteAllFromLayout(d->ui.loginBoxLayout);
    d->workerWaiting.wakeAll();
}
Example #7
0
void StartupView::showDetailsForItem( const QModelIndex & index )
{
  QLayout * layout = m_projectDetailView->layout();

  for( int i = 0; i < layout->count(); i++ )
  {
    delete layout->itemAt(i)->widget();
    layout->removeItem(layout->itemAt(i));
  }

  QString name = m_templateListModel->data(index,Qt::ToolTipRole).toString();

  QString description = m_templateListModel->data(index,Qt::WhatsThisRole).toString();

  if( ! name.isEmpty() )
  {
    auto nameLabel = new QLabel(name);

    nameLabel->setStyleSheet("QLabel { font: bold }");

    layout->addWidget(nameLabel);
  }

  if( ! description.isEmpty() )
  {
    auto descriptionLabel = new QTextEdit(description);
    
    descriptionLabel->setStyleSheet("QTextEdit { border: none; }");
    
    descriptionLabel->setReadOnly(true);

    layout->addWidget(descriptionLabel);
  }

}
Example #8
0
ActivityWidget::ActivityWidget(const QString& activity, QWidget* parent)
    : QWidget(parent)
    , m_ui(new Ui::ActivityWidget)
    , m_profilesConfig(KSharedConfig::openConfig("powermanagementprofilesrc", KConfig::SimpleConfig | KConfig::CascadeConfig))
    , m_activity(activity)
    , m_activityConsumer(new KActivities::Consumer(this))
    , m_actionEditWidget(new ActionEditWidget(QString("Activities/%1/SeparateSettings").arg(activity)))
{
    m_ui->setupUi(this);

    m_ui->separateSettingsLayout->addWidget(m_actionEditWidget);

    for (int i = 0; i < m_ui->specialBehaviorLayout->count(); ++i) {
        QWidget *widget = m_ui->specialBehaviorLayout->itemAt(i)->widget();
        if (widget) {
            widget->setVisible(false);
            connect(m_ui->specialBehaviorRadio, SIGNAL(toggled(bool)), widget, SLOT(setVisible(bool)));
        } else {
            QLayout *layout = m_ui->specialBehaviorLayout->itemAt(i)->layout();
            if (layout) {
                for (int j = 0; j < layout->count(); ++j) {
                    QWidget *widget = layout->itemAt(j)->widget();
                    if (widget) {
                        widget->setVisible(false);
                        connect(m_ui->specialBehaviorRadio, SIGNAL(toggled(bool)), widget, SLOT(setVisible(bool)));
                    }
                }
            }
        }
    }
//! [0]
static void paintLayout(QPainter *painter, QLayoutItem *item)
{
    QLayout *layout = item->layout();
    if (layout) {
        for (int i = 0; i < layout->count(); ++i)
            paintLayout(painter, layout->itemAt(i));
    }
    painter->drawRect(item->geometry());
}
void KoLineEditAction::setVisible(bool showAction)
{
    QLayout* currentLayout = defaultWidget()->layout();

    this->QAction::setVisible(showAction);

    for(int i=0;i<currentLayout->count();i++) {
        currentLayout->itemAt(i)->widget()->setVisible(showAction);
    }
    defaultWidget()->setVisible(showAction);
}
Example #11
0
QLayout *LayoutInfo::internalLayout(const QWidget *widget)
{
    QLayout *widgetLayout = widget->layout();
    if (widgetLayout && widget->inherits("Q3GroupBox")) {
        if (widgetLayout->count()) {
            widgetLayout = widgetLayout->itemAt(0)->layout();
        } else {
            widgetLayout = 0;
        }
    }
    return widgetLayout;
}
Example #12
0
void PhotoDrop::checkMoveButtons()
{
	std::cerr << "PhotoDrop::checkMoveButtons()";
	std::cerr << std::endl;
	/* locate mSelected in the set */
	QLayout *alayout = layout();
	if (!alayout)
	{
		std::cerr << "PhotoDrop::checkMoveButtons() No Layout";
		std::cerr << std::endl;
		return;
	}
	
	int count = alayout->count();
	if ((!mSelected) || (count < 2))
	{
    		buttonStatus(PHOTO_SHIFT_NO_BUTTONS);
		return;
	}

	QGridLayout *glayout = dynamic_cast<QGridLayout *>(alayout);
	if (!glayout)
	{
		std::cerr << "PhotoDrop::checkMoveButtons() not GridLayout... not much we can do!";
		std::cerr << std::endl;
    		buttonStatus(PHOTO_SHIFT_NO_BUTTONS);
		return;
	}

	int index = alayout->indexOf(mSelected);
	int selectedRow;
	int selectedColumn;
	int rowSpan;
	int colSpan;
	glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan);

	int maxRow = (count - 1) / mColumns;
	int maxCol = (count - 1) % mColumns;
	if ((selectedRow == 0) && (selectedColumn == 0))
	{
    		buttonStatus(PHOTO_SHIFT_RIGHT_ONLY);
	}
	else if ((selectedRow == maxRow) && (selectedColumn == maxCol))
	{
    		buttonStatus(PHOTO_SHIFT_LEFT_ONLY);
	}
	else
	{
    		buttonStatus(PHOTO_SHIFT_BOTH);
	}
}
Example #13
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);
        }
Example #14
0
	void MsgFormatterWidget::handleEmoPackChanged ()
	{
		const QString& emoPack = XmlSettingsManager::Instance ()
				.property ("SmileIcons").toString ();
		AddEmoticon_->setEnabled (!emoPack.isEmpty ());

		IEmoticonResourceSource *src = Core::Instance ().GetCurrentEmoSource ();
		if (!src)
			return;

		const QHash<QImage, QString>& images = src->GetReprImages (emoPack);

		QLayout *lay = SmilesTooltip_->layout ();
		if (lay)
		{
			while (lay->count ())
				delete lay->takeAt (0);
			delete lay;
		}

		QGridLayout *layout = new QGridLayout (SmilesTooltip_);
		layout->setSpacing (0);
		layout->setContentsMargins (1, 1, 1, 1);
		const int numRows = std::sqrt (static_cast<double> (images.size ())) + 1;
		int pos = 0;
		for (QHash<QImage, QString>::const_iterator i = images.begin (),
				end = images.end (); i != end; ++i)
		{
			const QIcon icon (QPixmap::fromImage (i.key ()));
			QAction *action = new QAction (icon, *i, this);
			action->setToolTip (*i);
			action->setProperty ("Text", *i);

			connect (action,
					SIGNAL (triggered ()),
					this,
					SLOT (insertEmoticon ()));

			QToolButton *button = new QToolButton ();
			button->setDefaultAction (action);

			layout->addWidget (button, pos / numRows, pos % numRows);
			++pos;
		}

		SmilesTooltip_->setLayout (layout);
		SmilesTooltip_->adjustSize ();
		SmilesTooltip_->setMaximumSize (SmilesTooltip_->sizeHint ());
	}
Example #15
0
 /**
  * Hide this view.
  */
 void PeaksViewer::hide() 
 {
   QLayout* layout = this->layout();
   const int size = layout->count();
   for(int i = 0; i < size; ++i)
   {
     auto item = layout->itemAt(i);
     if(auto widget = item->widget())
     {
       // This is important, otherwise the removed widgets sit around on the layout.
       widget->hide();
     }
   }
   QWidget::hide();
 }
Example #16
0
void LXQtGroupPopup::closeTimerSlot()
{
    bool button_has_dnd_hover = false;
    QLayout* l = layout();
    for (int i = 0; l->count() > i; ++i)
    {
        LXQtTaskButton const * const button = dynamic_cast<LXQtTaskButton const *>(l->itemAt(i)->widget());
        if (0 != button && button->hasDragAndDropHover())
        {
            button_has_dnd_hover = true;
            break;
        }
    }
    if (!button_has_dnd_hover)
        close();
}
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_layout_count (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   JsModuleUiV8QtBasic *self = _to_self (Args);
   if (self) {

      QLayout *layout = self->v8_to_qobject<QLayout> (Args.This ());
      if (layout) {

         result = v8::Number::New (layout->count ());
      }
   }

   return scope.Close (result);
}
Example #18
0
void QwtLegend::updateTabOrder()
{
    QLayout *contentsLayout = d_data->view->contentsWidget->layout();
    if ( contentsLayout )
    {
        // set tab focus chain

        QWidget *w = NULL;

        for ( int i = 0; i < contentsLayout->count(); i++ )
        {
            QLayoutItem *item = contentsLayout->itemAt( i );
            if ( w && item->widget() )
                QWidget::setTabOrder( w, item->widget() );

            w = item->widget();
        }
    }
}
Example #19
0
    /**
     * Slot called when the user wants to see the dialog for selecting
     * what columns are visible in the tables of peaks.
     */
    void PeaksViewer::showPeaksTableColumnOptions()
    {
      std::set<QString> areShown;

      // get the list of all the columns that are already shown
      QLayout* layout = this->layout();
      const int size = layout->count();
      for(int i = 0; i < size; ++i)
      {
        auto item = layout->itemAt(i);
        if(auto widget = item->widget())
        {
          if (auto table = dynamic_cast<PeaksWorkspaceWidget *>(widget))
          {
            auto shown = table->getShownColumns();
            areShown.insert(shown.begin(), shown.end());
          }
        }
      }

      // show the dialog box
      PeaksTableColumnsDialog dialog(this);
      dialog.setVisibleColumns(areShown);
      dialog.exec();
      auto result = static_cast<QDialog::DialogCode>(dialog.result());
      if (result != QDialog::DialogCode::Accepted)
        return;

      // set what columns to show
      auto toShow = dialog.getVisibleColumns();
      for(int i = 0; i < size; ++i)
      {
        auto item = layout->itemAt(i);
        if(auto widget = item->widget())
        {
          if (auto table = dynamic_cast<PeaksWorkspaceWidget *>(widget))
          {
            table->setShownColumns(toShow);
          }
        }
      }
    }
Example #20
0
void VideoWidget::SetSceneControl(BaseSceneController *sceneControlIn)
{
    //Remove previous scene button controls
    while(this->ui->annotationTools->count()>0)
    {
        //This item usually corresponds to the widget generated by the control factory
        QLayoutItem *item = this->ui->annotationTools->itemAt(0);
        QWidget *custom = item->widget();
        assert(custom!=NULL);
        cout << custom->metaObject()->className() << endl;

        //Also iterate through to get child widgets and directly close and remove them
        QLayout *wlayout = custom->layout();
        assert(wlayout!=NULL);
        while(wlayout->count())
        {
            int test = wlayout->count();
            QLayoutItem *citem = wlayout->itemAt(0);
            QWidget *childw = citem->widget();
            assert(childw!=NULL);
            childw->close();
            wlayout->removeItem(citem);
            delete childw;
        }

        custom->close();
        this->ui->annotationTools->removeItem(item);
        delete custom;
    }

    //Remove previous menu controls

    //Clear previous scene
    QGraphicsScene *oldScene = this->ui->graphicsView->scene();
    if(oldScene!=NULL) oldScene->clear();

    //Activate new scene button controls
    this->sceneControl = sceneControlIn;
    if(this->sceneControl!=NULL)
    {
        MouseGraphicsScene *scene = this->sceneControl->GetScene();
        if(scene != NULL)
        {
            this->ui->graphicsView->setScene(scene);
            this->sceneControl->Redraw();
            this->SetRawScale(0.3);
        }
        else
            this->ui->graphicsView->setScene(NULL);

        QWidget *controls = this->sceneControl->ControlsFactory(this);
        if(controls!=NULL)
            this->ui->annotationTools->addWidget(controls);
    }
    else
    {
        this->ui->graphicsView->setScene(NULL);
        this->SetSceneControl(new class LogoSceneController(this));
    }

}
Example #21
0
void ContentDialog::cycleContacts(bool forward, bool loop)
{
    Settings::getInstance().getGroupchatPosition();

    int index;
    QLayout* currentLayout;
    if (activeChatroomWidget->getFriend())
    {
        currentLayout = friendLayout->getLayoutOnline();
        index = friendLayout->indexOfFriendWidget(activeChatroomWidget, true);
        if (index == -1)
        {
            currentLayout = friendLayout->getLayoutOffline();
            index = friendLayout->indexOfFriendWidget(activeChatroomWidget, false);
        }
    }
    else
    {
        currentLayout = groupLayout.getLayout();
        index = groupLayout.indexOfSortedWidget(activeChatroomWidget);
    }

    if (!loop && index == currentLayout->count() - 1)
    {
        bool groupsOnTop = Settings::getInstance().getGroupchatPosition();
        bool offlineEmpty = friendLayout->getLayoutOffline()->count() == 0;
        bool onlineEmpty = offlineEmpty && ((friendLayout->getLayoutOnline()->count() == 0 && groupsOnTop) || !groupsOnTop);
        bool groupsEmpty = offlineEmpty && ((groupLayout.getLayout()->count() == 0 && !groupsOnTop) || groupsOnTop);

        if ((currentLayout == friendLayout->getLayoutOffline())
            || (currentLayout == friendLayout->getLayoutOnline() && groupsEmpty)
            || (currentLayout == groupLayout.getLayout() && onlineEmpty))
        {
            forward = !forward;
        }
    }

    index += forward ? 1 : -1;

    for (;;)
    {
        // Bounds checking.
        if (index < 0)
        {
            currentLayout = nextLayout(currentLayout, forward);
            index = currentLayout->count() - 1;
            continue;
        }
        else if (index >= currentLayout->count())
        {
            currentLayout = nextLayout(currentLayout, forward);
            index = 0;
            continue;
        }

        GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());

        if (chatWidget != nullptr && chatWidget != activeChatroomWidget)
            onChatroomWidgetClicked(chatWidget, false);

        return;
    }
}
Example #22
0
void PhotoDrop::moveRight()
{
	std::cerr << "PhotoDrop::moveRight()";
	std::cerr << std::endl;

	QLayout *alayout = layout();
	if (!alayout)
	{
		std::cerr << "PhotoDrop::moveRight() No Layout";
		std::cerr << std::endl;
		return;
	}

	QGridLayout *glayout = dynamic_cast<QGridLayout *>(alayout);
	if (!glayout)
	{
		std::cerr << "PhotoDrop::moveRight() not GridLayout... not much we can do!";
		std::cerr << std::endl;
		return;
	}
	
	int count = alayout->count();
	if ((!mSelected) || (count < 2))
	{
		std::cerr << "PhotoDrop::moveRight() Not enough items";
		std::cerr << std::endl;
		return;
	}

	int index = alayout->indexOf(mSelected);
	int selectedRow;
	int selectedColumn;
	int rowSpan;
	int colSpan;
	glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan);

	int maxRow = (count - 1) / mColumns;
	int maxCol = (count - 1) % mColumns;
	if ((selectedRow == maxRow) && (selectedColumn == maxCol))
	{
		std::cerr << "PhotoDrop::moveRight() Selected is last item";
		std::cerr << std::endl;
		return;
	}

	int swapRow = selectedRow;
	int swapColumn = selectedColumn + 1;

	if (swapColumn == mColumns)
	{
		swapRow++;
		swapColumn = 0;
	}

	std::cerr << "PhotoDrop::moveRight() Trying to swap (" << selectedRow << ",";
	std::cerr << selectedColumn << ") <-> (" << swapRow;
	std::cerr << "," << swapColumn << ")";
	std::cerr << std::endl;

	QLayoutItem *litem = glayout->itemAtPosition(swapRow, swapColumn);
	if (!litem)
	{
		std::cerr << "PhotoDrop::moveRight() No layout item to the right";
		std::cerr << std::endl;
		return;
	}

	QWidget *widget = litem->widget();

	if (!widget)
	{
		std::cerr << "PhotoDrop::moveRight() No item to the right";
		std::cerr << std::endl;
		return;
	}

	/* grab both items, and switch */
	std::cerr << "PhotoDrop::moveRight() could move index: " << index;
	std::cerr << std::endl;

	glayout->removeWidget(widget);
	glayout->removeWidget(mSelected);

	glayout->addWidget(widget, selectedRow, selectedColumn, Qt::AlignCenter);
	glayout->addWidget(mSelected, swapRow, swapColumn, Qt::AlignCenter);

	checkMoveButtons();
}
Example #23
0
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
{
    if (!activeChatroomWidget) {
        return;
    }

    int index = -1;
    FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);

    if (mode == Activity) {
        if (!friendWidget) {
            return;
        }

        QDate activityDate = getDateFriend(friendWidget->getFriend());
        index = static_cast<int>(getTime(activityDate));
        QWidget* widget = activityLayout->itemAt(index)->widget();
        CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);

        if (categoryWidget == nullptr || categoryWidget->cycleContacts(friendWidget, forward)) {
            return;
        }

        index += forward ? 1 : -1;

        for (;;) {
            // Bounds checking.
            if (index < 0) {
                index = LAST_TIME;
                continue;
            } else if (index > LAST_TIME) {
                index = 0;
                continue;
            }

            widget = activityLayout->itemAt(index)->widget();
            categoryWidget = qobject_cast<CategoryWidget*>(widget);

            if (categoryWidget != nullptr) {
                if (!categoryWidget->cycleContacts(forward)) {
                    // Skip empty or finished categories.
                    index += forward ? 1 : -1;
                    continue;
                }
            }

            break;
        }

        return;
    }

    QLayout* currentLayout = nullptr;
    CircleWidget* circleWidget = nullptr;

    if (friendWidget != nullptr) {
        const ToxPk& pk = friendWidget->getFriend()->getPublicKey();
        uint32_t circleId = Settings::getInstance().getFriendCircleID(pk);
        circleWidget = CircleWidget::getFromID(circleId);
        if (circleWidget != nullptr) {
            if (circleWidget->cycleContacts(friendWidget, forward)) {
                return;
            }

            index = circleLayout->indexOfSortedWidget(circleWidget);
            currentLayout = circleLayout->getLayout();
        } else {
            currentLayout = listLayout->getLayoutOnline();
            index = listLayout->indexOfFriendWidget(friendWidget, true);
            if (index == -1) {
                currentLayout = listLayout->getLayoutOffline();
                index = listLayout->indexOfFriendWidget(friendWidget, false);
            }
        }
    } else {
        GroupWidget* groupWidget = qobject_cast<GroupWidget*>(activeChatroomWidget);
        if (groupWidget != nullptr) {
            currentLayout = groupLayout.getLayout();
            index = groupLayout.indexOfSortedWidget(groupWidget);
        } else {
            return;
        };
    }

    index += forward ? 1 : -1;

    for (;;) {
        // Bounds checking.
        if (index < 0) {
            currentLayout = nextLayout(currentLayout, forward);
            index = currentLayout->count() - 1;
            continue;
        } else if (index >= currentLayout->count()) {
            currentLayout = nextLayout(currentLayout, forward);
            index = 0;
            continue;
        }

        // Go to the actual next index.
        if (currentLayout == listLayout->getLayoutOnline()
            || currentLayout == listLayout->getLayoutOffline()
            || currentLayout == groupLayout.getLayout()) {
            GenericChatroomWidget* chatWidget =
                qobject_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());

            if (chatWidget != nullptr)
                emit chatWidget->chatroomWidgetClicked(chatWidget);

            return;
        } else if (currentLayout == circleLayout->getLayout()) {
            circleWidget = qobject_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
            if (circleWidget != nullptr) {
                if (!circleWidget->cycleContacts(forward)) {
                    // Skip empty or finished circles.
                    index += forward ? 1 : -1;
                    continue;
                }
            }
            return;
        } else {
            return;
        }
    }
}
void MTPageNym_AltLocation::on_lineEditItemValue_textChanged(const QString & text)
{
    QLineEdit* edit = qobject_cast<QLineEdit*>(sender());

    if (edit)
    {
        // The data has just changed.

        // Update the internal data representation so the caller who
        // instantiated the wizard can get to it after the wizard is
        // closed.
        //
        PrepareOutputData();
        // ----------------------------------------------------------
        // Make sure there is at least one empty item in this group.
        //
        QWidget * pContactItemWidget = VPtr<QWidget>::asPtr(edit->property("contactitemwidget"));

        if (nullptr == pContactItemWidget)
        {
            return;
        }
        // ----------------------------------------------------------
        QComboBox * pComboBox = VPtr<QComboBox>::asPtr(pContactItemWidget->property("combo"));

        if (nullptr == pComboBox)
        {
            return;
        }
        // ----------------------------------------------------------
        GroupBoxContactItems * pGroupBox = VPtr<GroupBoxContactItems>::asPtr(pContactItemWidget->property("groupbox"));

        if (nullptr == pGroupBox)
        {
            return;
        }

        QLayout * pGroupBoxLayout = pGroupBox->layout();
        // ----------------------------------------------------------
        bool bAtLeastOneIsEmpty = false;

        for (int index_widget = 0; index_widget < pGroupBoxLayout->count(); ++index_widget)
        {
            QWidget *pItemWidget = pGroupBoxLayout->itemAt(index_widget)->widget();
            if (nullptr != pItemWidget)
            {
                const int nIndexLineEdit = 1; // todo hardcoding.
                QLayout * pItemLayout = pItemWidget->layout(); // Combo, Line Edit, Button
                QWidget *pLineEditWidget = pItemLayout->itemAt(nIndexLineEdit)->widget();

                if (nullptr != pLineEditWidget)
                {
                    QLineEdit * pLineEdit = dynamic_cast<QLineEdit *>(pLineEditWidget);
                    if (nullptr != pLineEdit)
                    {
                        const QString & qstrText = pLineEdit->text();

                        if (qstrText.isEmpty())
                        {
                            bAtLeastOneIsEmpty = true;
                            break;
                        }
                    }
                }
            }
        } // item widgets on group box.
        // -----------------------------------
        if (!bAtLeastOneIsEmpty)
        {
            QWidget * pNewItem = createSingleContactItem(pGroupBox, pComboBox->currentIndex());

            if (nullptr != pNewItem)
            {
                pGroupBoxLayout->addWidget(pNewItem);
            }
        }
    }
}
Example #25
0
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
{
    if (activeChatroomWidget == nullptr)
        return;

    int index = -1;
    FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(activeChatroomWidget);

    if (mode == Activity)
    {
        if (friendWidget == nullptr)
            return;

        QDate activityDate = getDateFriend(FriendList::findFriend(friendWidget->friendId));
        index = getTime(activityDate);
        CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(index)->widget());

        if (categoryWidget == nullptr || categoryWidget->cycleContacts(friendWidget, forward))
            return;

        index += forward ? 1 : -1;

        for (;;)
        {
            // Bounds checking.
            if (index < Today)
            {
                index = Never;
                continue;
            }
            else if (index > Never)
            {
                index = Today;
                continue;
            }

            CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(index)->widget());

            if (categoryWidget != nullptr)
            {
                if (!categoryWidget->cycleContacts(forward))
                {
                    // Skip empty or finished categories.
                    index += forward ? 1 : -1;
                    continue;
                }
            }

            break;
        }

        return;
    }

    QLayout* currentLayout = nullptr;
    CircleWidget* circleWidget = nullptr;

    if (friendWidget != nullptr)
    {
        circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId()));
        if (circleWidget != nullptr)
        {
            if (circleWidget->cycleContacts(friendWidget, forward))
                return;

            index = circleLayout->indexOfSortedWidget(circleWidget);
            currentLayout = circleLayout->getLayout();
        }
        else
        {
            currentLayout = listLayout->getLayoutOnline();
            index = listLayout->indexOfFriendWidget(friendWidget, true);
            if (index == -1)
            {
                currentLayout = listLayout->getLayoutOffline();
                index = listLayout->indexOfFriendWidget(friendWidget, false);
            }
        }
    }
    else
    {
        GroupWidget* groupWidget = dynamic_cast<GroupWidget*>(activeChatroomWidget);
        if (groupWidget != nullptr)
        {
            currentLayout = groupLayout.getLayout();
            index = groupLayout.indexOfSortedWidget(groupWidget);
        }
        else
        {
            return;
        };
    }

    index += forward ? 1 : -1;

    for (;;)
    {
        // Bounds checking.
        if (index < 0)
        {
            currentLayout = nextLayout(currentLayout, forward);
            index = currentLayout->count() - 1;
            continue;
        }
        else if (index >= currentLayout->count())
        {
            currentLayout = nextLayout(currentLayout, forward);
            index = 0;
            continue;
        }

        // Go to the actual next index.
        if (currentLayout == listLayout->getLayoutOnline() || currentLayout == listLayout->getLayoutOffline() || currentLayout == groupLayout.getLayout())
        {
            GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());

            if (chatWidget != nullptr)
                emit chatWidget->chatroomWidgetClicked(chatWidget);

            return;
        }
        else if (currentLayout == circleLayout->getLayout())
        {
            circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
            if (circleWidget != nullptr)
            {
                if (!circleWidget->cycleContacts(forward))
                {
                    // Skip empty or finished circles.
                    index += forward ? 1 : -1;
                    continue;
                }
            }
            return;
        }
        else
        {
            return;
        }
    }
}
Example #26
0
void
RadioWidget::refresh( const unicorn::Session& session )
{
    if ( session.isValid() )
    {
        m_movie->stop();

        if ( session.youRadio() )
        {
            unicorn::UserSettings us( session.user().name() );
            QString stationUrl = us.value( "lastStationUrl", "" ).toString();
            QString stationTitle = us.value( "lastStationTitle", tr( "A Radio Station" ) ).toString();

            ui->nowPlayingFrame->setVisible( !stationUrl.isEmpty() );

            RadioStation lastStation( stationUrl );
            lastStation.setTitle( stationTitle );

            ui->lastStation->setStation( lastStation, stationTitle );
            ui->lastStation->setObjectName( "station" );
            style()->polish( ui->lastStation );

            ui->library->setStation( RadioStation::library( session.user() ), tr( "My Library Radio" ), tr( "Music you know and love" ) );
            ui->mix->setStation( RadioStation::mix( session.user() ), tr( "My Mix Radio" ), tr( "Your library plus new music" ) );
            ui->rec->setStation( RadioStation::recommendations( session.user() ), tr( "My Recommended Radio" ), tr( "New music from Last.fm" ) );

            ui->friends->setStation( RadioStation::friends( session.user() ), tr( "My Friends' Radio" ), tr( "Music your friends like" ) );
            ui->neighbours->setStation( RadioStation::neighbourhood( session.user() ), tr( "My Neighbourhood Radio" ), tr ( "Music from listeners like you" ) );

            if ( m_currentUsername != session.user().name() )
            {
                m_currentUsername = session.user().name();

                // clear the recent stations
                QLayout* recentStationsLayout = ui->recentStations->layout();
                while ( recentStationsLayout->count() )
                {
                    QLayoutItem* item = recentStationsLayout->takeAt( 0 );
                    delete item->widget();
                    delete item;
                }

                // fetch recent stations
                connect( session.user().getRecentStations( MAX_RECENT_STATIONS ), SIGNAL(finished()), SLOT(onGotRecentStations()));
            }

            ui->stackedWidget->setCurrentWidget( ui->mainPage );
        }
        else
        {
            ui->listen->setVisible( session.registeredWebRadio() );

            ui->stackedWidget->setCurrentWidget( ui->nonSubPage );

            ui->title->setText( tr( "Subscribe to listen to radio, only %1 a month" ).arg( session.subscriptionPriceString() ) );
            ui->subscribe->setVisible( session.subscriberRadio() );
        }
    }
    else
    {
        ui->stackedWidget->setCurrentWidget( ui->spinnerPage );
        m_movie->start();
    }
}