ssize_t SortedVectorImpl::_indexOrderOf(const void* item, size_t* order) const
{
    // binary search
    ssize_t err = NAME_NOT_FOUND;
    ssize_t l = 0;
    ssize_t h = size()-1;
    ssize_t mid;
    const void* a = arrayImpl();
    const size_t s = itemSize();
    while (l <= h) {
        mid = l + (h - l)/2;
        const void* const curr = reinterpret_cast<const char *>(a) + (mid*s);
        const int c = do_compare(curr, item);
        if (c == 0) {
            err = l = mid;
            break;
        } else if (c < 0) {
            l = mid + 1;
        } else {
            h = mid - 1;
        }
    }
    if (order) *order = l;
    return err;
}
void DesktopWindow::onIndexesMoved(const QModelIndexList& indexes) {
    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto itemSize = delegate->itemSize();
    // remember the custom position for the items
    Q_FOREACH(const QModelIndex& index, indexes) {
        // Under some circumstances, Qt might emit indexMoved for
        // every single cells in the same row. (when QAbstractItemView::SelectItems is set)
        // So indexes list may contain several indixes for the same row.
        // Since we only care about rows, not individual cells,
        // let's handle column 0 of every row here.
        if(index.column() == 0) {
            auto file = proxyModel_->fileInfoFromIndex(index);
            QRect itemRect = listView_->rectForIndex(index);
            QPoint tl = itemRect.topLeft();
            QRect workArea = qApp->desktop()->availableGeometry(screenNum_);
            workArea.adjust(12, 12, -12, -12);

            // check if the position is occupied by another item
            auto existingItem = std::find_if(customItemPos_.cbegin(), customItemPos_.cend(), [tl](const std::pair<std::string, QPoint>& elem){
                return elem.second == tl;
            });

            if(existingItem == customItemPos_.cend() // don't put items on each other
                    && tl.x() >= workArea.x() && tl.y() >= workArea.y()
                    && tl.x() + itemSize.width() <= workArea.right() + 1 // for historical reasons (-> Qt doc)
                    && tl.y() + itemSize.height() <= workArea.bottom() + 1) { // as above
                customItemPos_[file->name()] = tl;
                // qDebug() << "indexMoved:" << name << index << itemRect;
            }
        }
    }
    saveItemPositions();
    queueRelayout();
}
void VectorImpl::_do_copy(void* dest, const void* from, size_t num) const
{
    if (!(mFlags & HAS_TRIVIAL_COPY)) {
        do_copy(dest, from, num);
    } else {
        memcpy(dest, from, num*itemSize());
    }
}
void DesktopWindow::removeBottomGap() {
    /************************************************************
     NOTE: Desktop is an area bounded from below while icons snap
     to its grid srarting from above. Therefore, we try to adjust
     the vertical cell margin to prevent relatively large gaps
     from taking shape at the desktop bottom.
     ************************************************************/
    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto itemSize = delegate->itemSize();
    qDebug() << "delegate:" << delegate->itemSize();
    QSize cellMargins = getMargins();
    int workAreaHeight = qApp->desktop()->availableGeometry(screenNum_).height()
                         - 24; // a 12-pix margin will be considered everywhere
    int cellHeight = itemSize.height() + listView_->spacing();
    int iconNumber = workAreaHeight / cellHeight;
    int bottomGap = workAreaHeight % cellHeight;
    /*******************************************
     First try to make room for an extra icon...
     *******************************************/
    // If one pixel is subtracted from the vertical margin, cellHeight
    // will decrease by 2 while bottomGap will increase by 2*iconNumber.
    // So, we can add an icon to the bottom once this inequality holds:
    // bottomGap + 2*n*iconNumber >= cellHeight - 2*n
    // From here, we get our "subtrahend":
    qreal exactNumber = ((qreal)cellHeight - (qreal)bottomGap)
                        / (2.0 * (qreal)iconNumber + 2.0);
    int subtrahend = (int)exactNumber + ((int)exactNumber == exactNumber ? 0 : 1);
    Settings& settings = static_cast<Application*>(qApp)->settings();
    int minCellHeight = settings.desktopCellMargins().height();
    if(subtrahend > 0
            && cellMargins.height() - subtrahend >= minCellHeight) {
        cellMargins -= QSize(0, subtrahend);
    }
    /***************************************************
     ... but if that can't be done, try to spread icons!
     ***************************************************/
    else {
        cellMargins += QSize(0, (bottomGap / iconNumber) / 2);
    }
    // set the new margins (if they're changed)
    delegate->setMargins(cellMargins);
    setMargins(cellMargins);
    // in case the text shadow is reset to (0,0,0,0)
    setShadow(settings.desktopShadowColor());
}
Exemple #5
0
// create arrray in array
Cbore& Cbore::array(std::size_t items)
{
    if ((cbor) && (itemSize(items) <= (maxLength - currentLength)))
    {
        writeTypeAndValue(CborBase::TypeArray, items);
    }

    return *this;
}
Exemple #6
0
Cbore& Cbore::tag(uint32_t tag)
{
    if ((cbor) && (itemSize(tag) <= (maxLength - currentLength)))
    {
        writeTypeAndValue(CborBase::TypeTag, tag);
    }

    return *this;
}
Exemple #7
0
Cbore& Cbore::value(const char* unit, std::size_t length)
{
    if ((itemSize(length) + length) <= (maxLength - currentLength))
    {
        writeTypeAndValue(CborBase::TypeString, length);
        writeBytes((const uint8_t*) unit, length);
    }

    return *this;
}
Exemple #8
0
Cbore& Cbore::item(const uint8_t* bytes, std::size_t length)
{
    if ((itemSize(length) + length) <= (maxLength - currentLength))
    {
        writeTypeAndValue(CborBase::TypeBytes, length);
        writeBytes(bytes, length);
    }

    return *this;
}
void DesktopWindow::childDropEvent(QDropEvent* e) {
    const QMimeData* mimeData = e->mimeData();
    bool moveItem = false;
    if(e->source() == listView_ && e->keyboardModifiers() == Qt::NoModifier) {
        // drag source is our list view, and no other modifier keys are pressed
        // => we're dragging desktop items
        if(mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) {
            QModelIndex dropIndex = listView_->indexAt(e->pos());
            if(dropIndex.isValid()) { // drop on an item
                QModelIndexList selected = selectedIndexes(); // the dragged items
                if(selected.contains(dropIndex)) { // drop on self, ignore
                    moveItem = true;
                }
            }
            else { // drop on a blank area
                moveItem = true;
            }
        }
    }
    if(moveItem) {
        e->accept();
    }
    else {
        auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
        auto grid = delegate->itemSize();
        Fm::FolderView::childDropEvent(e);
        // position dropped items successively, starting with the drop rectangle
        if(mimeData->hasUrls()
           && (e->dropAction() == Qt::CopyAction
               || e->dropAction() == Qt::MoveAction
               || e->dropAction() == Qt::LinkAction)) {
            QList<QUrl> urlList = mimeData->urls();
            for(int i = 0; i < urlList.count(); ++i) {
                std::string name = urlList.at(i).fileName().toUtf8().constData();
                if(!name.empty()) { // respect the positions of existing files
                    QString desktopDir = XdgDir::readDesktopDir() + QString(QLatin1String("/"));
                    if(!QFile::exists(desktopDir + QString::fromStdString(name))) {
                        QRect workArea = qApp->desktop()->availableGeometry(screenNum_);
                        workArea.adjust(12, 12, -12, -12);
                        QPoint pos = mapFromGlobal(e->pos());
                        alignToGrid(pos, workArea.topLeft(), grid, listView_->spacing());
                        if(i > 0)
                            pos.setY(pos.y() + grid.height() + listView_->spacing());
                        if(pos.y() + grid.height() > workArea.bottom() + 1) {
                            pos.setX(pos.x() + grid.width() + listView_->spacing());
                            pos.setY(workArea.top());
                        }
                        customItemPos_[name] = pos;
                    }
                }
            }
            saveItemPositions();
        }
    }
}
QSize KFileItemListView::availableIconSize() const
{
    const KItemListStyleOption& option = styleOption();
    const int iconSize = option.iconSize;
    if (itemLayout() == IconsLayout) {
        const int maxIconWidth = itemSize().width() - 2 * option.padding;
        return QSize(maxIconWidth, iconSize);
    }

    return QSize(iconSize, iconSize);
}
Exemple #11
0
suic::Size TabControl::ArrangeOverride(const suic::Size& size)
{
    ClearVisualChildren();

    _headerPanel.ClearLogicalChildren();

    int iItems = GetItems()->GetCount();
    suic::Rect finalRect(0, 0, size.cx, size.cy);

    if (_isAverage && iItems > 0)
    {
        TabItemPtr tabItem;
        int iWid = size.cx / iItems;
        suic::Size itemSize(iWid, _headerHeight);

        for (int i = 0; i < iItems - 1; ++i)
        {
            tabItem = GetItems()->GetItem(i).get();
            tabItem->SetDesiredSize(itemSize);
        }

        tabItem = GetItems()->GetItem(iItems - 1).get();

        itemSize.cx = size.cx - iWid * (iItems - 1);
        tabItem->SetDesiredSize(itemSize);

        for (int i = 0; i < iItems; ++i)
        {
            tabItem = GetItems()->GetItem(i).get();
            _headerPanel.AddLogicalChild(tabItem.get());
        }

        finalRect.bottom = finalRect.top + _headerHeight;

        AddVisualChild(&_headerPanel);
        _headerPanel.Arrange(finalRect);

        finalRect.top = finalRect.bottom;
        finalRect.bottom = size.cy;
    }

    TabItemPtr focusTab(_focusItem);

    if (focusTab)
    {  
        if (focusTab->GetTabContent())
        {
            AddVisualChild(focusTab->GetTabContent());
            focusTab->GetTabContent()->Arrange(finalRect);
        }
    }

    return size;
}
Exemple #12
0
void wxBitmapComboBox::DrawItem(wxDC &dc, int n) const
{
    wxSize itemSize(GetItemSize()); //((wxWindow*)GetLabelWindow())->GetClientSize().x, dy);

    wxPoint labelPos, bitmapPos;
    CalcLabelBitmapPos(n, itemSize, labelPos, bitmapPos);

    if (GetBitmap(n).Ok())
        dc.DrawBitmap(GetBitmap(n), bitmapPos.x, bitmapPos.y, true);
    if (!GetLabel(n).IsEmpty())
        dc.DrawText(GetLabel(n), labelPos.x, labelPos.y);
}
void DesktopWindow::loadItemPositions() {
    // load custom item positions
    customItemPos_.clear();
    Settings& settings = static_cast<Application*>(qApp)->settings();
    QString configFile = QString("%1/desktop-items-%2.conf").arg(settings.profileDir(settings.profileName())).arg(screenNum_);
    QSettings file(configFile, QSettings::IniFormat);

    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto grid = delegate->itemSize();
    QRect workArea = qApp->desktop()->availableGeometry(screenNum_);
    workArea.adjust(12, 12, -12, -12);
    char* dektopPath = Fm::Path::getDesktop().toStr();
    QString desktopDir = QString(dektopPath) + QString("/");
    g_free(dektopPath);

    std::vector<QPoint> usedPos;
    for(auto& item: customItemPos_) {
        usedPos.push_back(item.second);
    }

    // FIXME: this is inefficient
    Q_FOREACH(const QString& name, file.childGroups()) {
        if(!QFile::exists(desktopDir + name.toUtf8())) {
            // the file may have been removed from outside LXQT
            continue;
        }
        file.beginGroup(name);
        QVariant var = file.value("pos");
        if(var.isValid()) {
            QPoint customPos = var.toPoint();
            if(customPos.x() >= workArea.x() && customPos.y() >= workArea.y()
                    && customPos.x() + grid.width() <= workArea.right() + 1
                    && customPos.y() + grid.height() <= workArea.bottom() + 1) {
                // correct positions that are't aligned to the grid
                alignToGrid(customPos, workArea.topLeft(), grid, listView_->spacing());
                // FIXME: this is very inefficient
                while(std::find(usedPos.cbegin(), usedPos.cend(), customPos) != usedPos.cend()) {
                    customPos.setY(customPos.y() + grid.height() + listView_->spacing());
                    if(customPos.y() + grid.height() > workArea.bottom() + 1) {
                        customPos.setX(customPos.x() + grid.width() + listView_->spacing());
                        customPos.setY(workArea.top());
                    }
                }
                customItemPos_[name.toStdString()] = customPos;
                usedPos.push_back(customPos);
            }
        }
        file.endGroup();
    }
}
Exemple #14
0
Cbore& Cbore::value(int32_t unit)
{
    if ((itemSize(unit)) <= (maxLength - currentLength))
    {
        if (unit < 0)
        {
            writeTypeAndValue(CborBase::TypeNegative, -1 - unit);
        }
        else
        {
            writeTypeAndValue(CborBase::TypeUnsigned, unit);
        }
    }

    return *this;
}
Exemple #15
0
// insert integer
Cbore& Cbore::item(int32_t value)
{
    if (itemSize(value) <= (maxLength - currentLength))
    {
        if (value < 0)
        {
            writeTypeAndValue(CborBase::TypeNegative, -1 - value);
        }
        else
        {
            writeTypeAndValue(CborBase::TypeUnsigned, value);
        }
    }

    return *this;
}
ssize_t SortedVectorImpl::merge(const VectorImpl& vector)
{
    // naive merge...
    if (!vector.isEmpty()) {
        const void* buffer = vector.arrayImpl();
        const size_t is = itemSize();
        size_t s = vector.size();
        for (size_t i=0 ; i<s ; i++) {
            ssize_t err = add( reinterpret_cast<const char*>(buffer) + i*is );
            if (err<0) {
                return err;
            }
        }
    }
    return NO_ERROR;
}
Exemple #17
0
void Wizard::slotCheckPrograms()
{
    m_check.programList->setColumnCount(2);
    m_check.programList->setRootIsDecorated(false);
    m_check.programList->setHeaderHidden(true);
    QSize itemSize(20, fontMetrics().height() * 2.5);
    m_check.programList->setColumnWidth(0, 30);
    m_check.programList->setIconSize(QSize(24, 24));

    QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
    item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
    item->setSizeHint(0, itemSize);
    QString exepath = KStandardDirs::findExe("ffmpeg");
    if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
    else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
    item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
    item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

}
/*!
    Returns the minimum sizeHint.
*/
QSizeF HbListLayoutPrivate::minimumSizeHint()
{
    QSizeF sizeHint(0, 0);
    if (uniformSizedItems()) {
        QGraphicsLayoutItem *firstItem = mItems.value(0);
        if (firstItem) {
            sizeHint = firstItem->effectiveSizeHint(Qt::MinimumSize);
        }
    } else {
        int itemCount = mItems.count();
        for (int i = 0; i < itemCount; ++i) {       
            QSizeF itemSize(0, 0);  
            itemSize = mItems.at(i)->effectiveSizeHint(Qt::MinimumSize);

            if (itemSize.isValid()) {
                sizeHint.rwidth() = qMax(itemSize.width(), sizeHint.width());
                sizeHint.rheight() = qMax(sizeHint.height(), itemSize.height());
            }
        }
    }
    return sizeHint;
}
QSize FormViewDelegate::sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const
{
    Q_ASSERT(_formTreeModel);
    const bool topLevel = !index.parent().isValid();
    if (topLevel) {
        // For top level item, user can define in the Form::FormMain extraData the height of the item
        // If the item has a defined height, use it
        // Else check the empty root form height
        // Else use the default (10px)
        QSize itemSize(10, 10);
        Form::FormMain *form = _formTreeModel->formForIndex(index);
        if (form) {
            if (form->extraData().contains("rootitemextraheight")) {
                itemSize = QSize(10, form->extraData().value("rootitemextraheight").toInt());
            } else {
                if (form->rootFormParent()->extraData().contains("rootitemextraheight")) {
                    itemSize = QSize(10, form->rootFormParent()->extraData().value("rootitemextraheight").toInt());
                }
            }
        }
        return QStyledItemDelegate::sizeHint(option, index) + itemSize;
    }
    return QStyledItemDelegate::sizeHint(option, index);
}
// QListView does item layout in a very inflexible way, so let's do our custom layout again.
// FIXME: this is very inefficient, but due to the design flaw of QListView, this is currently the only workaround.
void DesktopWindow::relayoutItems() {
    displayNames_.clear();
    loadItemPositions(); // something may have changed
    // qDebug("relayoutItems()");
    if(relayoutTimer_) {
        // this slot might be called from the timer, so we cannot delete it directly here.
        relayoutTimer_->deleteLater();
        relayoutTimer_ = nullptr;
    }

    QDesktopWidget* desktop = qApp->desktop();
    int screen = 0;
    int row = 0;
    int rowCount = proxyModel_->rowCount();

    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto itemSize = delegate->itemSize();

    for(;;) {
        if(desktop->isVirtualDesktop()) {
            if(screen >= desktop->numScreens()) {
                break;
            }
        }
        else {
            screen = screenNum_;
        }
        QRect workArea = desktop->availableGeometry(screen);
        workArea.adjust(12, 12, -12, -12); // add a 12 pixel margin to the work area
        // qDebug() << "workArea" << screen <<  workArea;
        // FIXME: we use an internal class declared in a private header here, which is pretty bad.
        QPoint pos = workArea.topLeft();
        for(; row < rowCount; ++row) {
            QModelIndex index = proxyModel_->index(row, 0);
            int itemWidth = delegate->sizeHint(listView_->getViewOptions(), index).width();
            auto file = proxyModel_->fileInfoFromIndex(index);
            // remember display names of desktop entries and shortcuts
            if(file->isDesktopEntry() || file->isShortcut()) {
                displayNames_[index] = file->displayName();
            }
            auto name = file->name();
            auto find_it = customItemPos_.find(name);
            if(find_it != customItemPos_.cend()) { // the item has a custom position
                QPoint customPos = find_it->second;
                // center the contents vertically
                listView_->setPositionForIndex(customPos + QPoint((itemSize.width() - itemWidth) / 2, 0), index);
                // qDebug() << "set custom pos:" << name << row << index << customPos;
                continue;
            }
            // check if the current pos is alredy occupied by a custom item
            bool used = false;
            for(auto it = customItemPos_.cbegin(); it != customItemPos_.cend(); ++it) {
                QPoint customPos = it->second;
                if(QRect(customPos, itemSize).contains(pos)) {
                    used = true;
                    break;
                }
            }
            if(used) { // go to next pos
                --row;
            }
            else {
                // center the contents vertically
                listView_->setPositionForIndex(pos + QPoint((itemSize.width() - itemWidth) / 2, 0), index);
                // qDebug() << "set pos" << name << row << index << pos;
            }
            // move to next cell in the column
            pos.setY(pos.y() + itemSize.height() + listView_->spacing());
            if(pos.y() + itemSize.height() > workArea.bottom() + 1) {
                // if the next position may exceed the bottom of work area, go to the top of next column
                pos.setX(pos.x() + itemSize.width() + listView_->spacing());
                pos.setY(workArea.top());

                // check if the new column exceeds the right margin of work area
                if(pos.x() + itemSize.width() > workArea.right() + 1) {
                    if(desktop->isVirtualDesktop()) {
                        // in virtual desktop mode, go to next screen
                        ++screen;
                        break;
                    }
                }
            }
        }
        if(row >= rowCount) {
            break;
        }
    }

    if(!listView_->updatesEnabled()) {
        listView_->setUpdatesEnabled(true);
    }
}
Exemple #21
0
/*!
    \reimp
*/
QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
{
    Q_UNUSED(data);
    Q_D(QQuickPaintedItem);

    if (width() <= 0 || height() <= 0) {
        delete oldNode;
        if (d->textureProvider) {
            d->textureProvider->node = 0;
            d->textureProvider->fireTextureChanged();
        }
        return 0;
    }

    QSGPainterNode *node = static_cast<QSGPainterNode *>(oldNode);
    if (!node) {
        node = d->sceneGraphContext()->createPainterNode(this);
        d->node = node;
    }

    bool hasTextureSize = d->textureSize.width() > 0 && d->textureSize.height() > 0;

    // Use the compat mode if any of the compat things are set and
    // textureSize is 0x0.
    if (!hasTextureSize
        && (d->contentsScale != 1
            || (d->contentsSize.width() > 0 && d->contentsSize.height() > 0))) {
        QRectF br = contentsBoundingRect();
        node->setContentsScale(d->contentsScale);
        QSize size = QSize(qRound(br.width()), qRound(br.height()));
        node->setSize(size);
        node->setTextureSize(size);
    } else {
        // The default, use textureSize or item's size * device pixel ratio
        node->setContentsScale(1);
        QSize itemSize(qRound(width()), qRound(height()));
        node->setSize(itemSize);
        QSize textureSize = (hasTextureSize ? d->textureSize : itemSize)
                            * window()->effectiveDevicePixelRatio();
        node->setTextureSize(textureSize);
    }

    node->setPreferredRenderTarget(d->renderTarget);
    node->setFastFBOResizing(d->performanceHints & FastFBOResizing);
    node->setSmoothPainting(d->antialiasing);
    node->setLinearFiltering(d->smooth);
    node->setMipmapping(d->mipmap);
    node->setOpaquePainting(d->opaquePainting);
    node->setFillColor(d->fillColor);
    node->setDirty(d->dirtyRect);
    node->update();

    d->dirtyRect = QRect();

    if (d->textureProvider) {
        d->textureProvider->node = node;
        d->textureProvider->fireTextureChanged();
    }

    return node;
}
Exemple #22
0
void Wizard::slotCheckPrograms()
{
    QSize itemSize(20, fontMetrics().height() * 2.5);
    m_check.programList->setColumnWidth(0, 30);
    m_check.programList->setIconSize(QSize(24, 24));

    QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
    item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
    item->setSizeHint(0, itemSize);
    QString exepath = KStandardDirs::findExe("ffmpeg");
    if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
    else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

#ifndef Q_WS_MAC
    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("recordmydesktop"));
    item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvgrab"));
    item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);
#endif

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvdauthor"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);


    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("genisoimage or mkisofs"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("genisoimage").isEmpty()) {
        // no GenIso, check for mkisofs
        if (!KStandardDirs::findExe("mkisofs").isEmpty()) {
            item->setIcon(0, m_okIcon);
        } else item->setIcon(0, m_badIcon);
    } else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("xine"));
    item->setData(1, Qt::UserRole, i18n("Required to preview your DVD"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("xine").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    // set up some default applications
    QString program;
    if (KdenliveSettings::defaultimageapp().isEmpty()) {
        program = KStandardDirs::findExe("gimp");
        if (program.isEmpty()) program = KStandardDirs::findExe("krita");
        if (!program.isEmpty()) KdenliveSettings::setDefaultimageapp(program);
    }
    if (KdenliveSettings::defaultaudioapp().isEmpty()) {
        program = KStandardDirs::findExe("audacity");
        if (program.isEmpty()) program = KStandardDirs::findExe("traverso");
        if (!program.isEmpty()) KdenliveSettings::setDefaultaudioapp(program);
    }
    if (KdenliveSettings::defaultplayerapp().isEmpty()) {
        KService::Ptr offer = KMimeTypeTrader::self()->preferredService("video/mpeg");
        if (offer)
            KdenliveSettings::setDefaultplayerapp(KRun::binaryName(offer->exec(), true));
    }
}
Exemple #23
0
void Wizard::checkMltComponents()
{
    QSize itemSize(20, fontMetrics().height() * 2.5);
    m_mltCheck.programList->setColumnWidth(0, 30);
    m_mltCheck.programList->setIconSize(QSize(24, 24));


    QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);

    QTreeWidgetItem *meltitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Melt") + " (" + KdenliveSettings::rendererpath() + ')');
    meltitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
    meltitem->setSizeHint(0, itemSize);
    meltitem->setIcon(0, m_okIcon);


    Mlt::Repository *repository = Mlt::Factory::init();
    if (!repository) {
        mltitem->setData(1, Qt::UserRole, i18n("Cannot start the MLT video backend!"));
        mltitem->setIcon(0, m_badIcon);
        m_systemCheckIsOk = false;
        button(QWizard::NextButton)->setEnabled(false);
    }
    else {
        int mltVersion = (mltVersionMajor << 16) + (mltVersionMinor << 8) + mltVersionRevision;
        mltitem->setText(1, i18n("MLT version: %1", mlt_version_get_string()));
        mltitem->setSizeHint(0, itemSize);
        if (mlt_version_get_int() < 1792) {
            mltitem->setData(1, Qt::UserRole, i18n("Your MLT version is unsupported!!!"));
            mltitem->setIcon(0, m_badIcon);
            m_systemCheckIsOk = false;
            button(QWizard::NextButton)->setEnabled(false);
        }
        else if (mlt_version_get_int() < mltVersion) {
            mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to MLT %1.%2.%3", mltVersionMajor, mltVersionMinor, mltVersionRevision));
            mltitem->setIcon(0, m_badIcon);
        }
        else {
            mltitem->setData(1, Qt::UserRole, i18n("MLT video backend!"));
            mltitem->setIcon(0, m_okIcon);
        }

        // Retrieve the list of available transitions.
        Mlt::Properties *producers = repository->producers();
        QStringList producersItemList;
        for (int i = 0; i < producers->count(); ++i)
            producersItemList << producers->get_name(i);
        delete producers;

        Mlt::Properties *consumers = repository->consumers();
        QStringList consumersItemList;
        for (int i = 0; i < consumers->count(); ++i)
            consumersItemList << consumers->get_name(i);
        delete consumers;

        // SDL module
        QTreeWidgetItem *sdlItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("SDL module"));
        sdlItem->setData(1, Qt::UserRole, i18n("Required for Kdenlive"));
        sdlItem->setSizeHint(0, itemSize);
        
        if (!consumersItemList.contains("sdl")) {
            sdlItem->setIcon(0, m_badIcon);
            m_systemCheckIsOk = false;
            button(QWizard::NextButton)->setEnabled(false);
        }
        else {
            sdlItem->setIcon(0, m_okIcon);
        }

        // AVformat module
        QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
        avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
        avformatItem->setSizeHint(0, itemSize);
        Mlt::Consumer *consumer = NULL;
        Mlt::Profile p;
        if (consumersItemList.contains("avformat"))
            consumer = new Mlt::Consumer(p, "avformat");
        if (consumer == NULL || !consumer->is_valid()) {
            avformatItem->setIcon(0, m_badIcon);
            m_mltCheck.tabWidget->setTabEnabled(1, false);
        }
        else {
            avformatItem->setIcon(0, m_okIcon);
            consumer->set("vcodec", "list");
            consumer->set("acodec", "list");
            consumer->set("f", "list");
            consumer->start();
            QStringList result;
            Mlt::Properties vcodecs((mlt_properties) consumer->get_data("vcodec"));
            for (int i = 0; i < vcodecs.count(); ++i)
                result << QString(vcodecs.get(i));
            m_mltCheck.vcodecs_list->addItems(result);
            KdenliveSettings::setVideocodecs(result);
            result.clear();
            Mlt::Properties acodecs((mlt_properties) consumer->get_data("acodec"));
            for (int i = 0; i < acodecs.count(); ++i)
                result << QString(acodecs.get(i));
            m_mltCheck.acodecs_list->addItems(result);
            KdenliveSettings::setAudiocodecs(result);
            result.clear();
            Mlt::Properties formats((mlt_properties) consumer->get_data("f"));
            for (int i = 0; i < formats.count(); ++i)
                result << QString(formats.get(i));
            m_mltCheck.formats_list->addItems(result);
            KdenliveSettings::setSupportedformats(result);
            checkMissingCodecs();
            delete consumer;
        }

        // Image module
        QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
        imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
        imageItem->setSizeHint(0, itemSize);
        if (!producersItemList.contains("qimage")) {
            imageItem->setIcon(0, m_badIcon);
            imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
            imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
            imageItem->setSizeHint(0, itemSize);
            if (producersItemList.contains("pixbuf")) {
                imageItem->setIcon(0, m_badIcon);
            }
            else {
                imageItem->setIcon(0, m_okIcon);
            }
        }
        else {
            imageItem->setIcon(0, m_okIcon);
        }

        // Titler module
        QTreeWidgetItem *titleItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Title module"));
        titleItem->setData(1, Qt::UserRole, i18n("Required to work with titles"));
        titleItem->setSizeHint(0, itemSize);
        if (!producersItemList.contains("kdenlivetitle")) {
            KdenliveSettings::setHastitleproducer(false);
            titleItem->setIcon(0, m_badIcon);
        } else {
            titleItem->setIcon(0, m_okIcon);
            KdenliveSettings::setHastitleproducer(true);
        }
    }
}
Exemple #24
0
// Second-phase constructor
void CSendGrid::ConstructL(const TRect &aRect, TInt aResourceId) {
    CreateWindowL();
    SetRect(aRect);

    // Create grid and grid model
    iGrid = new (ELeave) CAknGrid;
            
    CAknGridM *gridM = new (ELeave) CAknGridM;
    iGrid->SetModel(gridM);
#ifdef PUTTY_SYM3
    iGrid->ConstructL(this, EAknListBoxSelectionGrid | EAknListBoxStylusMarkableList);
#else
    iGrid->ConstructL(this, EAknListBoxSelectionGrid);
#endif

    // Item size and grid layout
    TSize itemSize((aRect.Width()-2)/3, (aRect.Height()-2)/4);
    iGrid->SetLayoutL(EFalse, ETrue, ETrue, 3, 4, itemSize);
    iGrid->SetPrimaryScrollingType(CAknGridView::EScrollFollowsGrid);
    iGrid->SetSecondaryScrollingType(CAknGridView::EScrollFollowsGrid);
    iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff);

    // Set up grid layout
    AknListBoxLayouts::SetupStandardGrid(*iGrid);

    // Set initial grid content
    SetItemsL(aResourceId);

    // Label text cell, contains the key symbol
    const CFont *font = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
    TPoint text1Start(0, 0);
    TPoint text1End(itemSize.iWidth, font->FontMaxHeight());
    AknListBoxLayouts::SetupFormTextCell(*iGrid, iGrid->ItemDrawer(),
                                         1, // text pos
                                         font, 
                                         215, // color
                                         0, // left margin
                                         0, // right margin
                                         font->FontMaxAscent(), // baseline
                                         itemSize.iWidth, // width
                                         CGraphicsContext::ECenter, // alignment
                                         text1Start, 
                                         text1End);
    
    // Text cell for cell text from the resource file
    TPoint text2Start(0, font->FontMaxHeight());
    TPoint text2End(itemSize.iWidth, itemSize.iHeight);
    AknListBoxLayouts::SetupFormTextCell(*iGrid, iGrid->ItemDrawer(),
                                         2, // text pos
                                         font, 
                                         215, // color
                                         0, // left margin
                                         0, // right margin
                                         text2Start.iY + font->FontMaxAscent(), // baseline
                                         itemSize.iWidth, // width
                                         CGraphicsContext::ECenter, // alignment
                                         text2Start, 
                                         text2End);
    
    // Set size before changing colors -- according to the Forum Nokia
    // Knowledge Base article TSS000596 CAknGrid::SizeChanged() may override
    // this
    iGrid->SetRect(TRect(TPoint(1,1), Rect().Size() - TSize(2,2)));

    // Get grid item colors from the current skin. See Forum Nokia TSS000596.
    // Now if somebody could just tell me why CAknGrid doesn't do this by
    // default -- all other controls do...
    MAknsSkinInstance *skin = AknsUtils::SkinInstance();
    CFormattedCellListBoxData::TColors colors;
    AknsUtils::GetCachedColor(skin, colors.iText, KAknsIIDQsnTextColors,
                              EAknsCIQsnTextColorsCG9);
    AknsUtils::GetCachedColor(skin, colors.iHighlightedText,
                              KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11);
    iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
    iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(2, colors);

    // Enable and make visible
    iGrid->MakeVisible(ETrue);
    iGrid->SetFocus(ETrue);    
    ActivateL();
    iGrid->ActivateL();

    // Set new softkeys
    iCba = CEikButtonGroupContainer::Current();
    iCba->AddCommandSetToStackL(R_AVKON_SOFTKEYS_SELECT_BACK);
    iSetCba = ETrue;
    iCba->UpdateCommandObserverL(0, *this);
    iObsCba0 = ETrue;
    iCba->UpdateCommandObserverL(2, *this);
    iObsCba1 = ETrue;
    iCba->DrawDeferred();
}
Exemple #25
0
void Wizard::checkMltComponents()
{
    m_mltCheck.programList->setColumnCount(2);
    m_mltCheck.programList->setRootIsDecorated(false);
    m_mltCheck.programList->setHeaderHidden(true);
    QSize itemSize(20, fontMetrics().height() * 2.5);
    m_mltCheck.programList->setColumnWidth(0, 30);
    m_mltCheck.programList->setIconSize(QSize(24, 24));


    QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);

    QTreeWidgetItem *meltitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Melt") + " (" + KdenliveSettings::rendererpath() + ')');
    meltitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
    meltitem->setSizeHint(0, itemSize);
    meltitem->setIcon(0, m_okIcon);

    // Check MLT's installed producers
    QProcess checkProcess;
    checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
    if (!checkProcess.waitForStarted()) {
        meltitem->setIcon(0, m_badIcon);
        meltitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (melt)"));
        button(QWizard::NextButton)->setEnabled(false);
    } else {
        checkProcess.waitForFinished();
        QByteArray result = checkProcess.readAllStandardError();

        // Check MLT avformat module
        QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
        avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
        avformatItem->setSizeHint(0, itemSize);
        if (!result.contains("- avformat")) {
            avformatItem->setIcon(0, m_badIcon);
            m_mltCheck.tabWidget->setTabEnabled(1, false);
        } else {
            avformatItem->setIcon(0, m_okIcon);
            // Make sure we have MLT > 0.3.4
            bool recentMlt = false;
            int version = 0;
            QString mltVersion;
            QString exepath = KStandardDirs::findExe("pkg-config");
            if (!exepath.isEmpty()) {
                checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt++");
                if (!checkProcess.waitForStarted()) {
                    kDebug() << "// Error querying MLT's version";
                } else {
                    checkProcess.waitForFinished();
                    mltVersion = checkProcess.readAllStandardOutput();
                    version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
                    kDebug() << "// FOUND MLT's pkgconfig version: " << version;
                    if (version > 34) recentMlt = true;
                }
            }
            if (version == 0) {
                checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
                if (!checkProcess.waitForStarted()) {
                    kDebug() << "// Error querying MLT's version";
                } else {
                    checkProcess.waitForFinished();
                    mltVersion = checkProcess.readAllStandardError();
                    mltVersion = mltVersion.section('\n', 0, 0).simplified();
                    mltVersion = mltVersion.section(' ', -1).simplified();
                    version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
                    kDebug() << "// FOUND MLT version: " << version;
                    if (version >= 40) recentMlt = true;
                }
            }

            mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
            mltitem->setSizeHint(0, itemSize);
            if (version < recommendedMltVersion) {
                mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
                mltitem->setIcon(0, m_badIcon);
            } else {
                mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
                mltitem->setIcon(0, m_okIcon);
            }

            if (recentMlt) {
                // Check installed audio codecs
                QProcess checkProcess2;
                checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
                if (!checkProcess2.waitForStarted()) {
                    m_mltCheck.tabWidget->setTabEnabled(1, false);
                    kDebug() << "// Error parsing MLT's avformat codecs";
                } else {
                    checkProcess2.waitForFinished();
                    QByteArray codecList = checkProcess2.readAllStandardError();
                    QString acodecList(codecList);
                    QStringList result;
                    QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
                    for (int i = 0; i < alist.count(); i++) {
                        if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
                    }
                    m_mltCheck.acodecs_list->addItems(result);
                    KdenliveSettings::setAudiocodecs(result);
                    //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
                }
                // Check video codecs
                checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
                if (!checkProcess2.waitForStarted()) {
                    kDebug() << "// Error parsing MLT's avformat codecs";
                } else {
                    checkProcess2.waitForFinished();
                    QByteArray codecList = checkProcess2.readAllStandardError();
                    QString vcodecList(codecList);
                    QStringList result;
                    QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
                    for (int i = 0; i < vlist.count(); i++) {
                        if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
                    }
                    m_mltCheck.vcodecs_list->addItems(result);
                    KdenliveSettings::setVideocodecs(result);
                    //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
                }
                // Check formats
                checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
                if (!checkProcess2.waitForStarted()) {
                    kDebug() << "// Error parsing MLT's avformat codecs";
                } else {
                    checkProcess2.waitForFinished();
                    QByteArray codecList = checkProcess2.readAllStandardError();
                    QString vcodecList(codecList);
                    QStringList result;
                    QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
                    for (int i = 0; i < vlist.count(); i++) {
                        if (vlist.at(i).contains("- ")) {
                            QString format = vlist.at(i).section("- ", 1).simplified().toLower();
                            if (format.contains(',')) {
                                QStringList sub = format.split(',', QString::SkipEmptyParts);
                                for (int j = 0; j < sub.count(); j++)
                                    result.append(sub.at(j));
                            } else result.append(format);
                        }
                    }
                    m_mltCheck.formats_list->addItems(result);
                    KdenliveSettings::setSupportedformats(result);
                    //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
                }
            }

        }

        // Check MLT dv module
        QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
        dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
        dvItem->setSizeHint(0, itemSize);
        if (!result.contains("- libdv")) {
            dvItem->setIcon(0, m_badIcon);
        } else {
            dvItem->setIcon(0, m_okIcon);
        }

        // Check MLT image format module
        QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
        imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
        imageItem->setSizeHint(0, itemSize);
        if (!result.contains("- qimage")) {
            imageItem->setIcon(0, m_badIcon);
            imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
            imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
            imageItem->setSizeHint(0, itemSize);
            if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
            else imageItem->setIcon(0, m_okIcon);
        } else {
            imageItem->setIcon(0, m_okIcon);
        }
    }
}