示例#1
0
QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index)
{
    QVariant variant = index.data();
    if (!variant.isValid())
    {
        variant = index.data(Qt::DisplayRole);
        if (!variant.isValid())
        {
            return NULL;
        }
    }

    QWidget* editor = NULL;
    if (! (mTable->flags (index) & Qt::ItemIsEditable))
    {
        return mNotEditableDelegate.createEditor(qobject_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
    }

    std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display));
    if (delegateIt != mDelegates.end())
    {
        editor = delegateIt->second->createEditor(qobject_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
        DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, display);

        bool skip = false;
        if (qobject_cast<DropLineEdit*>(editor))
        {
            connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited()));
            connect(editor, SIGNAL(tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>&, const CSMDoc::Document*)),
                    proxy, SLOT(tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>&, const CSMDoc::Document*)));
            connect(proxy, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
                    this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
            skip = true;
        }
        if(!skip && qobject_cast<QCheckBox*>(editor))
        {
            connect(editor, SIGNAL(stateChanged(int)), proxy, SLOT(editorDataCommited()));
            skip = true;
        }
        if(!skip && qobject_cast<QPlainTextEdit*>(editor))
        {
            connect(editor, SIGNAL(textChanged()), proxy, SLOT(editorDataCommited()));
            skip = true;
        }
        if(!skip && qobject_cast<QComboBox*>(editor))
        {
            connect(editor, SIGNAL(currentIndexChanged (int)), proxy, SLOT(editorDataCommited()));
            skip = true;
        }
        if(!skip && qobject_cast<QAbstractSpinBox*>(editor))
        {
            connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited()));
            skip = true;
        }

        connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)), this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
        mProxys.push_back(proxy); //deleted in the destructor
    }
示例#2
0
Tagaro::ThemeSelector::ThemeSelector(Tagaro::ThemeProvider* provider)
	: m_provider(provider)
	, m_themeList(new QListView(this))
{
	//setup interface
	QVBoxLayout* layout = new QVBoxLayout;
	setLayout(layout);
	layout->addWidget(m_themeList);
#if 0
	if (options & Tagaro::ConfigDialog::WithNewStuffDownload)
	{
		QPushButton* knsButton = new QPushButton(KIcon("get-hot-new-stuff"), i18n("Get New Themes..."), this);
		knsButton->setEnabled(false); //KNS not implemented yet
		layout->addWidget(knsButton);
		connect(knsButton, SIGNAL(clicked()), SLOT(openNewStuffDialog()));
	}
#endif
	//setup theme list
	m_themeList->setModel(provider->model());
	m_themeList->setSelectionMode(QAbstractItemView::SingleSelection);
	updateSelectedTheme(provider->selectedTheme());
	connect(m_themeList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(storeSelection(QItemSelection)));
	connect(provider, SIGNAL(selectedThemeChanged(const Tagaro::Theme*)), SLOT(updateSelectedTheme(const Tagaro::Theme*)));
	//setup appearance of theme list (minimum size = 4 items)
	Tagaro::GraphicsDelegate* delegate = new Tagaro::GraphicsDelegate(m_themeList);
	const QSize itemSizeHint = delegate->sizeHint(QStyleOptionViewItem(), QModelIndex());
	const QSize scrollBarSizeHint = m_themeList->verticalScrollBar()->sizeHint();
	m_themeList->setMinimumSize(itemSizeHint.width() + 2 * scrollBarSizeHint.width(), 4 * itemSizeHint.height());
}
示例#3
0
void DateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const
{
    QStyleOptionViewItem noption = QStyleOptionViewItem(option);
    noption.textElideMode =  Qt::ElideNone;

    QStyledItemDelegate::paint(painter, noption, index);
}
示例#4
0
int toResultTableView::visibleRows() const
{
    // TODO this is ugly hack and needs some validation
    //this->visibleRegion();
    int h = sizeHintForRow(0);
    QAbstractItemDelegate *d = itemDelegate();
    QSize s = d->sizeHint(QStyleOptionViewItem(), QModelIndex());
    int hh = height();
    int hhh = s.height();
    int rows = hh / s.height() + 1;
    if (rows < toConfigurationNewSingle::Instance().option(ToConfiguration::Database::InitialFetchInt).toInt())
        return toConfigurationNewSingle::Instance().option(ToConfiguration::Database::InitialFetchInt).toInt();
    return rows;
}
bool PsiFilteredContactListView::handleKeyPressEvent(QKeyEvent* e)
{
	updateKeyboardModifiers(e);

	switch (e->key()) {
	case Qt::Key_Enter:
	case Qt::Key_Return: {
		if (state() == EditingState)
			return false;

		QModelIndex currentIndex = this->currentIndex();
		if (currentIndex.isValid()) {
			// TODO: probably should select the item from the filteredListView_
			// in the contactListView_ as well
			activate(currentIndex);
		}
		return true;
	}
	case Qt::Key_Home: {
		selectIndex(0);
		return true;
	}
	case Qt::Key_End: {
		selectIndex(model()->rowCount()-1);
		return true;
	}
	case Qt::Key_Up:
	case Qt::Key_Down: {
		moveSelection(1, e->key() == Qt::Key_Up ? Backward : Forward);
		return true;
	}
	case Qt::Key_PageUp:
	case Qt::Key_PageDown: {
		int delta = 0;
		QModelIndex index = model()->index(0, 0, QModelIndex());
		if (index.isValid()) {
			int itemHeight = itemDelegate()->sizeHint(QStyleOptionViewItem(), index).height();
			if (itemHeight)
				delta = viewport()->height() / itemHeight;
		}
		moveSelection(delta, e->key() == Qt::Key_PageUp ? Backward : Forward);
		return true;
	}
	default:
		;
	}

	return false;
}
示例#6
0
 void drawPrimitive(PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0) const {
     const QStyleOptionViewItem *vopt = NULL;
     switch (element) {
         case PE_PanelItemViewItem:
             // Highlight the current, selected item with a different background in an item view if the highlight current item property is set
             if (option->state & QStyle::State_HasFocus && (vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) && widget && widget->property("highlight_current_item").toBool()) {
                 QColor color = vopt->palette.color(QPalette::Normal, QPalette::Highlight);
                 QStyleOptionViewItem opt = QStyleOptionViewItem(*vopt);
                 if (color.lightness() > 128)
                     color = color.darker(widget->property("highlight_current_item").toInt());
                 else
                     color = color.lighter(125);
                 opt.palette.setColor(QPalette::Highlight, color);
                 return QProxyStyle::drawPrimitive(element, &opt, painter, widget);
             }
             break;
         default:
             break;
     }
     return QProxyStyle::drawPrimitive(element, option, painter, widget);
 }
void terminalDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    if (index.column() != 3) {
        QSqlRelationalDelegate::paint(painter, option, index);
    } else {
        const QAbstractItemModel *model = index.model();
        QStyleOptionViewItem opt = QStyleOptionViewItem(option);
        int width = 22;
        int height = 22;
        int x = opt.rect.x();
        int y = opt.rect.y()+4;
        opt.rect = QRect(x, y, width, height);
             if(model->data(index).toBool())
            opt.state = QStyle::State_On;
        QApplication::style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, painter);
        }
       // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves


}
示例#8
0
QSize
GridItemDelegate::itemSize() const
{
    return sizeHint( QStyleOptionViewItem(), m_model->index( 0, 0 ) );
}
示例#9
0
void WrapTextDelegate::paint( QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
	int x1, y1, x2, y2; //(x1, y1) is the upper-left corner, (x2, y2) the lower-right
	option.rect.getCoords(&x1, &y1, &x2, &y2);
	p->save();

	int lineWidths = 4;
	// draw a line below each row
	p->setPen( QPen( QBrush("#9CC"), lineWidths) );
	p->drawLine(x1, y2, x2, y2);
	// draw a line between each column
	p->setPen( QPen( QBrush("#CCC"), lineWidths) );
	p->drawLine( x2, y1+((y2-y1)/5), x2, y2-((y2-y1)/5));

	p->restore();

	if( index.isValid() && index.column() == BachAssetItem::Column_Info )
	{
		BachAsset ba = ((RecordSuperModel*)(index.model()))->getRecord(index);

		QRect pathRect(x1+5, y1+5, x2-x1-10, ((y2-y1)/3)-10);
		QRect tagsRect(pathRect.x(), pathRect.y()+pathRect.height()+10, x2-x1-10, y2-y1-10);
		QRect keywordsRect(pathRect.x(), pathRect.y()+pathRect.height()+30, x2-x1-10, y2-y1-10);
		QRect fullSize;

		p->save();
		QItemDelegate::drawBackground( p, option, index );
		if( option.state & QStyle::State_Selected )
			p->setPen( option.palette.highlightedText().color() );
		else
			p->setPen( option.palette.text().color() );

		p->drawText( pathRect, Qt::TextWordWrap, ba.path(), &fullSize );
		p->drawText( tagsRect, Qt::TextWordWrap, QString("Tags: ")+ba.tags(), &fullSize );
		p->drawText( keywordsRect, Qt::TextWordWrap, QString("Keywords: ")+ba.cachedKeywords(), &fullSize );

		p->setPen( QPen( QBrush("#9CC"), 2) );
		p->drawLine(x1+10, y1+((y2-y1)/3), x2-10, y1+((y2-y1)/3));

		//QRect dateRect(tagsRect.bottomRight().x()-40,tagsRect.bottomRight().y()-14, tagsRect.bottomRight().x(), tagsRect.bottomRight.y());

		QFont curFont = option.font;
		p->setFont( QFont(curFont.family(), curFont.pointSize()-2, curFont.weight(), true ) );
		curFont.setPointSize( curFont.pointSize()-1 );
		p->setPen( QColor("#CCC") );

		QRect sizeRect(x1+20,y2-20,x1+100,y2-4);
		p->drawText( sizeRect, Qt::TextWordWrap, QString::number(ba.width())+"x"+QString::number(ba.height()), &fullSize );

		p->setFont(option.font);

		p->restore();
		return;
	}
	else
	{
		QStyleOptionViewItem newOption = QStyleOptionViewItem(option);
		newOption.displayAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
		newOption.decorationAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
		return QItemDelegate::paint( p, newOption, index );
	}
}
示例#10
0
QSize ExpandingDelegate::basicSizeHint(const QModelIndex &index) const
{
    return QItemDelegate::sizeHint(QStyleOptionViewItem(), index);
}