Пример #1
0
bool ListBoxDnd::dropEvent( QDropEvent * event )
{
    if ( dragInside ) {
    
	if ( dMode & NullDrop ) { // combined with Move, a NullDrop will delete an item
	    event->accept();
	    emit dropped( 0 ); // a NullDrop
	    return TRUE;
	}
	
	QPoint pos = event->pos();
	QListBoxItem * after = itemAt( pos );

	if ( ListBoxItemDrag::decode( event, (QListBox *) src, after ) ) {
	    event->accept();
	    QListBox * src = (QListBox *) this->src;
	    QListBoxItem * item = ( after ? after->next() : src->firstItem() );
	    src->setCurrentItem( item );
	    emit dropped( item ); // ###FIX: Supports only one item!
	}
    }

    line->hide();
    dragInside = FALSE;

    return TRUE;
}
Пример #2
0
//=====================================
// XKeyboard get index of item text
//-------------------------------------
int XKeyboard::getItem ( QComboBox* widget, const QString& item ) {
	QListBox* list = widget -> listBox();
	for (int i=0;i<widget->count();i++) {
	if (list->item(i)->text() == item ) {
		return (i);
	}
	}
	return (0);
}
Пример #3
0
void ListBoxDnd::updateLine( const QPoint & dragPos )
{
    QListBox * src = (QListBox *) this->src;
    QListBoxItem *item = itemAt( dragPos );

    int ypos = item ? 
	( src->itemRect( item ).bottom() - ( line->height() / 2 ) ) : 
	( src->itemRect( ((QListBox *)src)->firstItem() ).top() );

    line->resize( src->viewport()->width(), line->height() );
    line->move( 0, ypos );
}
Пример #4
0
void KActionSelector::moveItem(QListBoxItem *item)
{
    QListBox *lbFrom = item->listBox();
    QListBox *lbTo;
    if(lbFrom == d->availableListBox)
        lbTo = d->selectedListBox;
    else if(lbFrom == d->selectedListBox)
        lbTo = d->availableListBox;
    else //?! somewhat unlikely...
        return;

    InsertionPolicy p = (lbTo == d->availableListBox) ? d->availableInsertionPolicy : d->selectedInsertionPolicy;

    lbFrom->takeItem(item);
    lbTo->insertItem(item, insertionIndex(lbTo, p));
    lbTo->setFocus();
    lbTo->setCurrentItem(item);

    if(p == Sorted)
        lbTo->sort();
    if(lbTo == d->selectedListBox)
        emit added(item);
    else
        emit removed(item);
}
Пример #5
0
void TabDialog::setupTab3()
{
    QVBox *tab3 = new QVBox( this );
    tab3->setMargin( 5 );
    tab3->setSpacing( 5 );
    
    (void)new QLabel( QString( "Open %1 with:" ).arg( filename ), tab3 );

    QListBox *prgs = new QListBox( tab3 );
    for ( unsigned int i = 0; i < 30; i++ ) {
        QString prg = QString( "Application %1" ).arg( i );
        prgs->insertItem( prg );
    }
    prgs->setCurrentItem( 3 );

    (void)new QCheckBox( QString( "Open files with the extension '%1' always with this application" ).arg( fileinfo.extension() ), tab3 );

    addTab( tab3, "Applications" );
}
Пример #6
0
bool KActionSelector::eventFilter(QObject *o, QEvent *e)
{
    if(d->keyboardEnabled && e->type() == QEvent::KeyPress)
    {
        if((((QKeyEvent *)e)->state() & Qt::ControlButton))
        {
            switch(((QKeyEvent *)e)->key())
            {
            case Key_Right:
                buttonAddClicked();
                break;
            case Key_Left:
                buttonRemoveClicked();
                break;
            case Key_Up:
                buttonUpClicked();
                break;
            case Key_Down:
                buttonDownClicked();
                break;
            default:
                return QWidget::eventFilter(o, e);
                break;
            }
            return true;
        }
        else if(o->inherits("QListBox"))
        {
            switch(((QKeyEvent *)e)->key())
            {
            case Key_Return:
            case Key_Enter:
                QListBox *lb = (QListBox *)o;
                int index = lb->currentItem();
                if(index < 0)
                    break;
                moveItem(lb->item(index));
                return true;
            }
        }
    }
    return QWidget::eventFilter(o, e);
}
Пример #7
0
QListBoxItem * ListBoxDnd::itemAt( QPoint pos )
{
    QListBox * src = (QListBox *) this->src;
    QListBoxItem * result = src->itemAt( pos );
    QListBoxItem * last = src->item( src->count() - 1 );
    int i = src->index( result );

    if ( result && ( pos.y() < (src->itemRect(result).top() + src->itemHeight(i)/2) ) )
	result = result->prev();
    else if ( !result && pos.y() > src->itemRect( last ).bottom() )
	result = last;

    return result;
}
void MidiManagerView::updateLists()
{
	vector<MidiClientInfo> *clients = manager.clients();
	vector<MidiClientInfo>::iterator i;

// keep selection over updating
	MidiManagerItem *src =
		(MidiManagerItem *)widget->inputsListBox->item(widget->inputsListBox->currentItem());
	MidiManagerItem *dest =
		(MidiManagerItem *)widget->outputsListBox->item(widget->outputsListBox->currentItem());

	long srcID = src?src->info.ID:0;
	long destID = dest?dest->info.ID:0;

// clear everything, and rebuild
	itemMap.clear();
	widget->inputsListBox->clear();
	widget->outputsListBox->clear();
	for(i = clients->begin(); i != clients->end(); i++)
	{
		QListBox *box;
		if(i->direction == mcdPlay)
			box = widget->inputsListBox;
		else
			box = widget->outputsListBox;

		MidiManagerItem *item = new MidiManagerItem(*i);
		itemMap[item->info.ID] = item;
		box->insertItem(item);
	}
	delete clients;

// restore selection
	if(srcID && itemMap[srcID])
		widget->inputsListBox->setSelected(itemMap[srcID],true);
	if(destID && itemMap[destID])
		widget->outputsListBox->setSelected(itemMap[destID],true);
	connectionWidget->repaint();
}
Пример #9
0
bool KateFileSelector::eventFilter( QObject* o, QEvent *e )
{
  /*
      This is rather unfortunate, but:
      QComboBox does not support setting the size of the listbox to something
      reasonable. Even using listbox->setVariableWidth() does not yield a
      satisfying result, something is wrong with the handling of the sizehint.
      And the popup is rather useless, if the paths are only partly visible.
  */
  QListBox *lb = cmbPath->listBox();
  if ( o == lb && e->type() == QEvent::Show ) {
    int add = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
    int w = QMIN( mainwin->width(), lb->contentsWidth() + add );
    lb->resize( w, lb->height() );
    // TODO - move the listbox to a suitable place if nessecary
    // TODO - decide if it is worth caching the size while untill the contents
    //        are changed.
  }
  // TODO - same thing for the completion popup?
  return QWidget::eventFilter( o, e );
}
Пример #10
0
KScienceSetup::KScienceSetup(  QWidget *parent, const char *name )
	: KDialogBase( parent, name, true, i18n( "Setup Science Screen Saver" ),
	  Ok|Cancel|Help, Ok, true ), saver( 0 )
{
	readSettings();
	initModeInfo();

	QWidget *main = makeMainWidget();

	QHBoxLayout *lt  = new QHBoxLayout( main, 0, spacingHint());
	QVBoxLayout *ltm = new QVBoxLayout;
	lt->addLayout( ltm );
	QVBoxLayout *ltc = new QVBoxLayout;
	lt->addLayout( ltc );

	// mode
	QLabel *label = new QLabel( i18n("Mode:"), main );
	ltm->addWidget( label );

	QListBox *c = new QListBox( main );
	for(int i = 0; i<MAX_MODES; i++)
		c->insertItem( modeInfo[i].name );
	c->setCurrentItem( mode );
	c->setFixedHeight( 5 * c->fontMetrics().height() );
	connect( c, SIGNAL( highlighted( int ) ), SLOT( slotMode( int ) ) );
	ltm->addWidget( c );

	// inverse
	QCheckBox *cbox = checkInverse = new QCheckBox( i18n("Inverse"), main );
	cbox->setEnabled( modeInfo[mode].inverseEnable );
	cbox->setChecked( inverse[mode] );
	connect( cbox, SIGNAL( clicked() ), SLOT( slotInverse() ) );
	ltm->addWidget( cbox );

	// gravity
	cbox = checkGravity = new QCheckBox( i18n("Gravity"), main );
	cbox->setChecked( gravity[mode] );
	connect( cbox, SIGNAL( clicked() ), SLOT( slotGravity() ) );
	ltm->addWidget( cbox );

	// hide background
	cbox = checkHideBG = new QCheckBox( i18n("Hide background"), main );
	cbox->setChecked( hideBG[mode] );
	connect( cbox, SIGNAL( clicked() ), SLOT( slotHideBG() ) );
	ltm->addWidget( cbox );
	ltm->addStretch();

	// size
	label = new QLabel( i18n("Size:"), main );
	ltc->addWidget( label );

	slideSize = new QSlider(9, 50, 5, size[mode], QSlider::Horizontal,
                                main );
	slideSize->setMinimumSize( 90, 20 );
    slideSize->setTickmarks(QSlider::Below);
    slideSize->setTickInterval(5);
	connect( slideSize, SIGNAL( sliderMoved( int ) ),
		SLOT( slotSize( int ) ) );
	connect( slideSize, SIGNAL( sliderPressed() ),
		SLOT( slotSliderPressed() ) );
	connect( slideSize, SIGNAL( sliderReleased() ),
		SLOT( slotSliderReleased() ) );

	ltc->addWidget( slideSize );

	// intensity
	label = new QLabel( i18n("Intensity:"), main );
	ltc->addWidget( label );

	slideIntensity = new QSlider(0, 10, 1, intensity[mode],
                                     QSlider::Horizontal, main );
	slideIntensity->setMinimumSize( 90, 20 );
    slideIntensity->setTickmarks(QSlider::Below);
    slideIntensity->setTickInterval(1);
	connect( slideIntensity, SIGNAL( sliderMoved( int ) ),
		SLOT( slotIntensity( int )) );
	connect( slideIntensity, SIGNAL( sliderPressed() ),
		SLOT( slotSliderPressed() ) );
	connect( slideIntensity, SIGNAL( sliderReleased() ),
		SLOT( slotSliderReleased() ) );
	ltc->addWidget( slideIntensity );

	// speed
	label = new QLabel( i18n("Speed:"), main );
	ltc->addWidget( label );

	slideSpeed = new QSlider(0, SCI_MAX_SPEED, 10, speed[mode],
                             QSlider::Horizontal, main );
	slideSpeed->setMinimumSize( 90, 20 );
    slideSpeed->setTickmarks(QSlider::Below);
    slideSpeed->setTickInterval(10);
	connect( slideSpeed, SIGNAL( sliderMoved( int ) ),
		SLOT( slotSpeed( int ) ) );
	ltc->addWidget( slideSpeed );

	// motion
	label = new QLabel( i18n("Motion:"), main );
	ltc->addWidget( label );

	QHBoxLayout *ltcm = new QHBoxLayout;
	ltc->addLayout( ltcm );

	slideMoveX = new QSlider(0, SCI_MAX_MOVE, 5, moveX[mode],
                                 QSlider::Horizontal, main );
	slideMoveX->setMinimumSize( 40, 20 );
    slideMoveX->setTickmarks(QSlider::Below);
    slideMoveX->setTickInterval(5);
	connect( slideMoveX, SIGNAL( sliderMoved( int ) ),
		SLOT( slotMoveX( int ) ) );
	ltcm->addWidget( slideMoveX );

	slideMoveY = new QSlider(0, SCI_MAX_MOVE, 5, moveY[mode],
                                QSlider::Horizontal, main );
	slideMoveY->setMinimumSize( 40, 20 );
    slideMoveY->setTickmarks(QSlider::Below);
    slideMoveY->setTickInterval(5);
	connect( slideMoveY, SIGNAL( sliderMoved( int ) ),
		SLOT( slotMoveY( int ) ) );
	ltcm->addWidget( slideMoveY );

	ltc->addStretch();

	// preview
	preview = new KPreviewWidget( main );
	preview->setFixedSize( 220, 170 );
	QPixmap p( locate("data", "kscreensaver/pics/kscience.png") );
	if( p.isNull() )
		preview->setBackgroundColor( black );
	else
		preview->setBackgroundPixmap( p );
	preview->show();	// otherwise saver does not get correct size
	lt->addWidget( preview );

	// let the preview window display before creating the saver
	kapp->processEvents();

	saver = new KScienceSaver( preview->winId(), true, !p.isNull() );
	preview->notifySaver( saver );
}
Пример #11
0
void KURLBarItem::paint(QPainter *p)
{
    QListBox *box = listBox();
    int w = width(box);
    static const int margin = KDialog::spacingHint();

    // draw sunken selection
    if(isCurrent() || isSelected())
    {
        int h = height(box);

        QBrush brush = box->colorGroup().brush(QColorGroup::Highlight);
        p->fillRect(0, 0, w, h, brush);
        QPen pen = p->pen();
        QPen oldPen = pen;
        pen.setColor(box->colorGroup().mid());
        p->setPen(pen);

        p->drawPoint(0, 0);
        p->drawPoint(0, h - 1);
        p->drawPoint(w - 1, 0);
        p->drawPoint(w - 1, h - 1);

        p->setPen(oldPen);
    }

    if(m_parent->iconSize() < KIcon::SizeMedium)
    {
        // small icon -> draw icon next to text

        // ### mostly cut & paste of QListBoxPixmap::paint() until Qt 3.1
        // (where it will properly use pixmap() instead of the internal pixmap)
        const QPixmap *pm = pixmap();
        int yPos = QMAX(0, (height(box) - pm->height()) / 2);

        p->drawPixmap(margin, yPos, *pm);
        if(!text().isEmpty())
        {
            QFontMetrics fm = p->fontMetrics();
            if(pm->height() < fm.height())
                yPos = fm.ascent() + fm.leading() / 2;
            else
                yPos = pm->height() / 2 - fm.height() / 2 + fm.ascent();

            yPos += margin;
            int stringWidth = box->width() - pm->width() - 2 - (margin * 2);
            QString visibleText = KStringHandler::rPixelSqueeze(text(), fm, stringWidth);
            int xPos = pm->width() + margin + 2;

            if(isCurrent() || isSelected())
            {
                p->setPen(box->colorGroup().highlight().dark(115));
                p->drawText(xPos + (QApplication::reverseLayout() ? -1 : 1), yPos + 1, visibleText);
                p->setPen(box->colorGroup().highlightedText());
            }

            p->drawText(xPos, yPos, visibleText);
        }
        // end cut & paste (modulo pixmap centering)
    }

    else
    {
        // big icons -> draw text below icon
        int y = margin;
        const QPixmap *pm = pixmap();

        if(!pm->isNull())
        {
            int x = (w - pm->width()) / 2;
            x = QMAX(x, margin);
            p->drawPixmap(x, y, *pm);
        }

        if(!text().isEmpty())
        {
            QFontMetrics fm = p->fontMetrics();
            y += pm->height() + fm.height() - fm.descent();

            int stringWidth = box->width() - (margin * 2);
            QString visibleText = KStringHandler::rPixelSqueeze(text(), fm, stringWidth);
            int x = (w - fm.width(visibleText)) / 2;
            x = QMAX(x, margin);

            if(isCurrent() || isSelected())
            {
                p->setPen(box->colorGroup().highlight().dark(115));
                p->drawText(x + (QApplication::reverseLayout() ? -1 : 1), y + 1, visibleText);
                p->setPen(box->colorGroup().highlightedText());
            }

            p->drawText(x, y, visibleText);
        }
    }
}
Пример #12
0
/////////////////////////////////////////////////////////////////////////////////////////////////
// Trade dialog class
/////////////////////////////////////////////////////////////////////////////////////////////////
TradeDialog::TradeDialog(net::GameState *gamestate, const PlayerState* me, const PlayerState* other, QWidget *parent, const char * name) : QDialog(parent, name, TRUE)
{
	setCaption("Make a trade!");

	QGridLayout *grid = new QGridLayout(this, 4, 2, 5, 10, "grid");

	const Game_Base & base = gamestate->get_base();

	QLabel * lbl = NULL;

	// titles

	lbl = new QLabel("Your inventory", this);
	grid->addWidget( lbl, 0, 0, Qt::AlignCenter );

	lbl = new QLabel( other->get_name() + QString("'s inventory") , this);
	grid->addWidget( lbl , 0, 1, Qt::AlignCenter );

	// buttons

	QPushButton *okbtn = new QPushButton ("Request Trade", this);
	connect( okbtn, SIGNAL(clicked()), SLOT(accept()));
	grid->addWidget( okbtn, 3, 0, Qt::AlignCenter );

	QPushButton *cancelbtn = new QPushButton( "Cancel", this);
	connect(cancelbtn, SIGNAL(clicked()), SLOT(reject()));
	grid->addWidget( cancelbtn, 3, 1, Qt::AlignCenter );

	// money spinboxes

	QHBox * lhbox = new QHBox(this);
	lhbox->setSpacing(5);
	new QLabel("Money:", lhbox);
	_my_spin = new QSpinBox( 0, me->get_money(), 1, lhbox);
	grid->addWidget(lhbox, 2, 0, Qt::AlignCenter );
	
	QHBox * rhbox = new QHBox(this);
	rhbox->setSpacing(5);
	new QLabel("Money:", rhbox);
	_their_spin = new QSpinBox( 0, other->get_money(), 1, rhbox);
	grid->addWidget(rhbox, 2, 1, Qt::AlignCenter );


	net::PropertyList_t::const_iterator it;



	// current player's inventory

	QListBox* llbox = _my_list = new QListBox(this);
	llbox->setSelectionMode( QListBox::Multi );
	llbox->setMinimumHeight(100);

	const net::PropertyList_t & props = me->get_owned_properties();
	for(it = props.begin(); it != props.end(); ++it) {
		net::Property_t id = *it;
		if(id == 255 || id == 254) {
			_my_trans.push_back(id);
			llbox->insertItem( QString("Get out of Jail card - ") + QString::number(id - 253) );
		} else {
			const std::string* name = base.name(id);
			if(name != NULL) {
				_my_trans.push_back(id);
				llbox->insertItem( *name );
			}
		}
	}

	grid->addWidget(llbox, 1, 0, Qt::AlignHCenter | Qt::AlignTop );


	QListBox* rlbox = _their_list = new QListBox(this);
	rlbox->setSelectionMode( QListBox::Multi );
	rlbox->setMinimumHeight(100);

	const net::PropertyList_t tprops = other->get_owned_properties();
	for(it = tprops.begin(); it != tprops.end(); ++it) {
		net::Property_t id = *it;
		if(id == 255 || id == 254) {
			_their_trans.push_back(id);
			rlbox->insertItem( QString("Get out of Jail card - ") + QString::number(id - 253) );
		} else {
			const std::string* name = base.name(id);
			if(name != NULL) {
				_their_trans.push_back(id);
				rlbox->insertItem( *name );
			}
		}
	}


	grid->addWidget(rlbox, 1, 1, Qt::AlignHCenter | Qt::AlignTop );

}