void
DocumentXML::clear()
{
  document_.removeChild(document_.documentElement());
  setModified(true);

  if(!children().isEmpty()) {
    QObjectList childList = children();
    while(!childList.isEmpty()) {
      delete childList.takeFirst();
    }
  }
}
// from: http://stackoverflow.com/questions/5298614/change-the-size-of-qt-dialogs-depending-on-the-platform
void MainWindow::adjustAppearanceToOS(QWidget *rootWidget)
{
    int fontSize = -1;
    #ifdef Q_OS_WIN
        fontSize = 8;
    #elif __APPLE__
        fontSize = 12;
    #elif __linux
        fontSize = 11;
    #endif

    if (rootWidget == NULL)
        return;

    QObject *child = NULL;
    QObjectList Containers;
    QObject *container  = NULL;
    QStringList DoNotAffect;

    // Make an exception list (Objects not to be affected)
    // DoNotAffect.append("widgetName");

    // Append root to containers
    Containers.append(rootWidget);

    while (!Containers.isEmpty())
    {
        container = Containers.takeFirst();
        if (container != NULL)
            for (int i = 0; i < container->children().size(); i++)
            {
                child = container->children()[i];
                if (!child->isWidgetType() || DoNotAffect.contains(child->objectName()))
                    continue;

                if (child->children().size() > 0)
                    Containers.append(child);

                // (if the object is not of the correct type, it will be NULL)
                QLabel *label = qobject_cast<QLabel *>(child);
                if (label != NULL)
                {
                    label->setText(label->text().replace(QRegExp("font-size:.*;"), ""));

                    QFont font = label->font();
                    font.setPointSize(fontSize);
                    label->setFont(font);
                }
            }
    }
}
Exemple #3
0
void
DocumentXML::clear()
{
  // Remove the root element
  document_.removeChild(document_.documentElement());
  // Notify that the document has been modified
  setModified(true);

  // Delete all children of the QObject
  if(!children().isEmpty()) {
    QObjectList childList = children();
    while(!childList.isEmpty()) {
      delete childList.takeFirst();
    }
  }
}
Exemple #4
0
Item::~Item()
{
  //  cout << name() << " deleting children" << endl;

  if (!children().isEmpty()) {
    QObjectList childList = children();
    while(!childList.isEmpty() ) {
      delete childList.takeFirst();
    }
  }

  //  cout << name() << " deleting listviewitem" << endl;

  delete treeWidgetItem_;
  // Remove the QTreeWidgetItem from the map to Item
  itemMap_.erase(treeWidgetItem_);

  //  cout << name() << " deleting" << endl;
}
void XDataWidget::setFields(const XData::FieldList &f)
{
    fields_.clear();

    // delete all child widgets
    QObjectList objlist = queryList();
    while (!objlist.isEmpty()) {
        delete objlist.takeFirst();
    }


    QVBoxLayout* vert = new QVBoxLayout(this);
    if (!instructions_.isEmpty()) {
        QLabel* l = new QLabel(instructions_, this);
        l->setWordWrap(true);
        l->setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::LinksAccessibleByMouse);
        connect(l,SIGNAL(linkActivated(const QString&)),SLOT(linkActivated(const QString&)));
        vert->addWidget(l);
    }
    QWidget *fields = new QWidget(this);
    vert->addWidget(fields);
    if ( f.count() ) {
        QGridLayout *grid = new QGridLayout(fields, 3, f.count(), 0, 3);

        int row = 0;
        XData::FieldList::ConstIterator it = f.begin();
        for ( ; it != f.end(); ++it, ++row) {
            XDataField *f;
            switch ( (*it).type() ) {
            case XData::Field::Field_Boolean:
                f = new XDataField_Boolean(*it, grid, row, this);
                break;
            case XData::Field::Field_Fixed:
                f = new XDataField_Fixed(*it, grid, row, this);
                break;
            case XData::Field::Field_Hidden:
                f = new XDataField_Hidden(*it);
                break;
            case XData::Field::Field_JidSingle:
                f = new XDataField_JidSingle(*it, grid, row, this);
                break;
            case XData::Field::Field_ListMulti:
                f = new XDataField_ListMulti(*it, grid, row, this);
                break;
            case XData::Field::Field_ListSingle:
                f = new XDataField_ListSingle(*it, grid, row, this);
                break;
            case XData::Field::Field_TextMulti:
                f = new XDataField_TextMulti(*it, grid, row, this);
                break;
            case XData::Field::Field_JidMulti:
                f = new XDataField_JidMulti(*it, grid, row, this);
                break;
            case XData::Field::Field_TextPrivate:
                f = new XDataField_TextPrivate(*it, grid, row, this);
                break;

            default:
                f = new XDataField_TextSingle(*it, grid, row, this);
            }
            fields_.append(f);
        }
    }
}
void QtHelpers::GenAdjustWidgetAppearanceToOS(QWidget *rootWidget)
{
    if (rootWidget == NULL)
            return;

        QObject *child = NULL;
        QObjectList Containers;
        QObject *container  = NULL;
        QStringList DoNotAffect;

        // Make an exception list (Objects not to be affected)
        DoNotAffect.append("aboutTitleLabel");     // about Dialog
        DoNotAffect.append("aboutVersionLabel");   // about Dialog
        DoNotAffect.append("aboutCopyrightLabel"); // about Dialog
        DoNotAffect.append("aboutUrlLabel");       // about Dialog
        DoNotAffect.append("aboutLicenseLabel");   // about Dialog

        // Set sizes according to OS:
    #ifdef __APPLE__
        int ButtonHeight = 35;
        int cmbxHeight = 30;
        QFont cntrlFont("Myriad Pro", 14);
        QFont txtFont("Myriad Pro", 14);
    #elif _WIN32 // Win XP/7
        int ButtonHeight = 24;
        int cmbxHeight = 20;
        QFont cntrlFont("MS Shell Dlg 2", 8);
        QFont txtFont("MS Shell Dlg 2", 8);
    #else
        int ButtonHeight = 24;
        int cmbxHeight = 24;
        QFont cntrlFont("Ubuntu Condensed", 10);
        QFont txtFont("Ubuntu", 10);
    #endif

        // Append root to containers
        Containers.append(rootWidget);
        while (!Containers.isEmpty())
        {
            container = Containers.takeFirst();
            if (container != NULL)
            {
                for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++)
                {
                    child = container->children()[ChIdx];
                    if (!child->isWidgetType() || DoNotAffect.contains(child->objectName()))
                        continue;
                    // Append containers to Stack for recursion
                    if (child->children().size() > 0)
                        Containers.append(child);
                    else
                    {
                        // Cast child object to button and label
                        // (if the object is not of the correct type, it will be NULL)
                        QPushButton *button = qobject_cast<QPushButton *>(child);
                        QLabel *label = qobject_cast<QLabel *>(child);
                        QComboBox *cmbx = qobject_cast<QComboBox *>(child);
                        QLineEdit *ln = qobject_cast<QLineEdit *>(child);
                        QTreeWidget *tree = qobject_cast<QTreeWidget *>(child);
                        QPlainTextEdit *plain = qobject_cast<QPlainTextEdit *>(child);
                        QCheckBox *check = qobject_cast<QCheckBox *>(child);
                        if (button != NULL)
                        {
                            button->setMinimumHeight(ButtonHeight); // Win
                            button->setMaximumHeight(ButtonHeight); // Win
                            button->setFont(cntrlFont);
                        }
                        else if (cmbx != NULL)
                        {
                            cmbx->setFont(cntrlFont);
                            cmbx->setMaximumHeight(cmbxHeight);
                        }
                        else if (label != NULL)
                            label->setFont(txtFont);
                        else if (ln != NULL)
                            ln->setFont(txtFont);
                        else if (tree != NULL)
                        {
                            tree->header()->setFont(txtFont);
                        }
                        else if (plain != NULL)
                            plain->setFont(txtFont);
                        else if (check != NULL)
                            check->setFont(txtFont);
                    }
                }
            }
        }
}