Exemple #1
0
bool PrefListBox::eventFilter(QObject*, QEvent* event)
{
    if (event->type() == QEvent::ChildRemoved) {
        emit ItemMoved();
    }
    return false;
}
Exemple #2
0
PreferenceWindow::PreferenceWindow(Preferences* p)
                 :QWidget(NULL)
{
    prefs = p;
    l = new PrefListBox;
    l->setDragDropMode(QAbstractItemView::InternalMove);

    QGroupBox* dictlistbox = new QGroupBox("dictionaries");
    QVBoxLayout* dictlistlayout = new QVBoxLayout;
    dictlistlayout->addWidget(l);
    dictlistbox->setLayout(dictlistlayout);
    connect(l, SIGNAL(itemChanged(QListWidgetItem*)), 
            this, SLOT(CheckChanged(QListWidgetItem*)));
    connect(l, SIGNAL(ItemMoved()), 
            this, SLOT(ItemMoved()));

    QGroupBox* dictbox = new QGroupBox("dictionary path");
    dictpath = new QLineEdit;
    connect(dictpath, SIGNAL(returnPressed()),
            this, SLOT(DictPathChanged()));
    dictpath->setText(prefs->path);
    QVBoxLayout* dictlayout = new QVBoxLayout;
    dictlayout->addWidget(dictpath);
    dictbox->setLayout(dictlayout);
    
    QGroupBox* popupbox = new QGroupBox("popup window");
    QGridLayout* popuplayout = new QGridLayout;
    popuplayout->addWidget(new QLabel("x"), 0, 0);
    popuplayout->addWidget(new QLabel("y"), 1, 0);
    popuplayout->addWidget(new QLabel("w"), 2, 0);
    popuplayout->addWidget(new QLabel("h"), 3, 0);

    xline = new QLineEdit;
    xline->setText(QString("%1").arg(prefs->px));
    yline = new QLineEdit;
    yline->setText(QString("%1").arg(prefs->py));
    wline = new QLineEdit;
    wline->setText(QString("%1").arg(prefs->pw));
    hline = new QLineEdit;
    hline->setText(QString("%1").arg(prefs->ph));

    connect(xline, SIGNAL(textChanged(QString)),
            this, SLOT(PopupChanged()));
    connect(yline, SIGNAL(textChanged(QString)),
            this, SLOT(PopupChanged()));
    connect(wline, SIGNAL(textChanged(QString)),
            this, SLOT(PopupChanged()));
    connect(hline, SIGNAL(textChanged(QString)),
            this, SLOT(PopupChanged()));

    popuplayout->addWidget(xline, 0, 1);
    popuplayout->addWidget(yline, 1, 1);
    popuplayout->addWidget(wline, 2, 1);
    popuplayout->addWidget(hline, 3, 1);
    popupbox->setLayout(popuplayout);

    QVBoxLayout* tboxes = new QVBoxLayout;
    tboxes->addWidget(dictbox);
    tboxes->addWidget(popupbox);
    tboxes->addStretch(0);

    QHBoxLayout* ll = new QHBoxLayout;
    ll->addWidget(dictlistbox);
    ll->addLayout(tboxes);
    setLayout(ll);
}
void ScrolledListView::TrackRearrangement(BPoint point)
{
/***
	static const rgb_color indicatorColor = { 128, 128, 128, 256 };
***/

	// sanity clause
	if (selection < 0)
		return;

	// first, because the selection might have changed, redraw the whole thing
	BRect bounds = Bounds();
	Draw(bounds);

	// track the movement
	int newIndex = -1;
	while (true) {
		uint32 buttons;
		GetMouse(&point, &buttons, true);
			// UNDOCUMENTED FACT ABOUT GetMouse():
			// If the "checkQueue" argument is true, GetMouse() will cause
			// the invalid region to be redrawn!  In our case we don't want
			// that, because sometimes it means the indicator gets clobbered,
			// since scrolling invalidates areas.
			// BUT, if "checkQueue" is false, something goes wrong after
			// you've held the mouse down for a while (about six seconds on
			// my machine), and the tracking loop starts to respond really
			// slowly.  Is the queue filling up?  Maybe with MOUSE_MOVED
			// messages, but I tried cleaning them out and it didn't help.
			// It didn't even delay the onset of the problem.
			// SO:  We leave "checkQueue" as true, just like the example in
			// the BeBook, but we do this GetMouse() call *before* we do
			// our drawing.  This means a bit of flashiness since items can
			// be drawn twice, but guarantees that everything will look right.
		if (buttons == 0)
			break;

		newIndex = TrackInsertionStep(point, newIndex);
		}

/***
	// track the movement
	float itemHeight = ItemHeight();
	int32 numItems = NumItems();
	int32 newIndex = -1;
	uint32 buttons = 1;
	while (buttons) {
		// autoscroll
		if (point.y < bounds.top) {
			if (bounds.top > 0) {
				ScrollBy(0, -itemHeight);
				bounds.OffsetBy(0, -itemHeight);
				}
			point.y = bounds.top;
			}
		else if (point.y > bounds.bottom) {
			if (bounds.bottom < numItems * itemHeight - 1) {
				ScrollBy(0, itemHeight);
				bounds.OffsetBy(0, itemHeight);
				}
			point.y = bounds.bottom + 1;	// need the +1 to let it get beyond the last item
			}

		// figure out where it is now
		int32 curNewIndex = point.y / itemHeight;
		if (curNewIndex < 0)
			curNewIndex = 0;
		else if (curNewIndex > numItems)	// can move beyond the last item
			curNewIndex = numItems;

		GetMouse(&point, &buttons, true);
			// UNDOCUMENTED FACT ABOUT GetMouse():
			// If the "checkQueue" argument is true, GetMouse() will cause
			// the invalid region to be redrawn!  In our case we don't want
			// that, because sometimes it means the indicator gets clobbered,
			// since scrolling invalidates areas.
			// BUT, if "checkQueue" is false, something goes wrong after
			// you've held the mouse down for a while (about six seconds on
			// my machine), and the tracking loop starts to respond really
			// slowly.  Is the queue filling up?  Maybe with MOUSE_MOVED
			// messages, but I tried cleaning them out and it didn't help.
			// It didn't even delay the onset of the problem.
			// SO:  We leave "checkQueue" as true, just like the example in
			// the BeBook, but we do this GetMouse() call *before* we do
			// our drawing.  This means a bit of flashiness since items can
			// be drawn twice, but guarantees that everything will look right.
			// We can get away with updating "point" and "buttons" here (instead
			// of at the end of the loop as you'd normally do) because they're
			// not used from here on.

		// draw
		if (curNewIndex != newIndex) {
			// redraw items bordering old indicator, to clear it
			if (newIndex >= 0) {
				if (newIndex > 0)
					DrawItemAt(newIndex - 1);
				if (newIndex < numItems)
					DrawItemAt(newIndex);
				else {
					// need to clean up bottom
					BRect bottomRect = bounds;
					bottomRect.top = newIndex * itemHeight;
					FillRect(bottomRect, B_SOLID_LOW);
					}
				}

			// draw new indicator
			newIndex = curNewIndex;
			SetHighColor(indicatorColor);
			SetPenSize(2.0);
			float indicatorY = newIndex * itemHeight;
			StrokeLine(BPoint(bounds.left, indicatorY),
			           BPoint(bounds.right, indicatorY));
			SetPenSize(1.0);
			}

		// go around again
		Flush();
		snooze(50000);	// BeBook-recommended snooze time is 20000, but we don't need to be that greedy
		}
***/

	// move the item
	if (newIndex >= 0) {
		if (newIndex > selection)
			newIndex -= 1;
		if (newIndex != selection) {
			ItemMoved(selection, newIndex);
			selection = newIndex;
			}
		}

	Invalidate();
}