예제 #1
0
int FOListView::cal_step_size(QListViewItem *item)
{
  QListViewItem *cur_item=item;
  int parent=0;
  while(cur_item->parent())
  {
    ++parent;
    cur_item=cur_item->parent();
  }
  return treeStepSize() * parent;
}
예제 #2
0
void K3bListView::placeEditor( K3bListViewItem* item, int col )
{
  ensureItemVisible( item );
  QRect r = itemRect( item );

  r.setX( contentsToViewport( QPoint(header()->sectionPos( col ), 0) ).x() );
  r.setWidth( header()->sectionSize( col ) - 1 );

  // check if the column is fully visible
  if( visibleWidth() < r.right() )
    r.setRight(visibleWidth());

  r = QRect( viewportToContents( r.topLeft() ), r.size() );

  if( item->pixmap( col ) ) {
    r.setX( r.x() + item->pixmap(col)->width() );
  }

  // the tree-stuff is painted in the first column
  if( col == 0 ) {
    r.setX( r.x() + item->depth() * treeStepSize() );
    if( rootIsDecorated() )
      r.setX( r.x() + treeStepSize() );
  }

  if( item->needButton(col) ) {
    prepareButton( item, col );
    m_editorButton->setFixedHeight( r.height() );
    // for now we make a square button
    m_editorButton->setFixedWidth( m_editorButton->height() );
    r.setWidth( r.width() - m_editorButton->width() );
    moveChild( m_editorButton, r.right(), r.y() );
  }

  if( QWidget* editor = prepareEditor( item, col ) ) {
    editor->resize( r.size() );
    //    editor->resize( QSize( r.width(), editor->minimumSizeHint().height() ) );
    moveChild( editor, r.x(), r.y() );
  }
}
void toListView::editPrint(void)
{
#if 0
    TOPrinter printer;

    std::map<int, int> PageColumns;
    std::map<int, toTreeWidgetItem *> PageItems;

    int column = 0;
    int tree = rootIsDecorated() ? treeStepSize() : 0;
    int page = 1;
    PageColumns[1] = 0;
    toTreeWidgetItem *item = PageItems[1] = firstChild();

    printer.setCreator(tr(TOAPPNAME));
    QPainter painter(&printer);

    while ((item = printPage(&printer, &painter, item, column, tree, page++, false)))
    {
        PageColumns[page] = column;
        PageItems[page] = item;
    }

    printer.setMinMax(1, page - 1);
    printer.setFromTo(1, page - 1);
    if (printer.setup())
    {
        QList<int> pages;
        for (int i = printer.fromPage(); i <= printer.toPage() || (printer.toPage() == 0 && i < page); i++)
            pages += i;

        for (QList<int>::iterator pageit = pages.begin(); pageit != pages.end(); pageit++)
        {
            page = *pageit;
            item = PageItems[page];
            column = PageColumns[page];

            printPage(&printer, &painter, item, column, tree, page, true);
            printer.newPage();
            painter.resetXForm();
            qApp->processEvents();
            QString str = tr("Printing page %1").arg(page);
            toStatusMessage(str, false, false);
        }
        painter.end();
        toStatusMessage(tr("Done printing"), false, false);
    }
#endif
}
void TeQtViewsListView::contentsDragMoveEvent(QDragMoveEvent *e)
{
	if(pressedThemeItem_)
		pressedThemeItem_->setOpen(themeOpen_);

	if(e->source() != viewport())
	{
		e->ignore();
		e->acceptAction(false);
		return;
	}

    QPoint p = contentsToViewport(((QDragMoveEvent*)e)->pos());
    TeQtCheckListItem *item = (TeQtCheckListItem*)itemAt(p);
    if (item)
	{
		if (p.x() < treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)) + itemMargin())
		{
			e->ignore();
			e->acceptAction(false);
		}
		else
		{
			if(item->getType() == TeQtCheckListItem::THEME || item->getType() == TeQtCheckListItem::VIEW)
			{
				e->accept();
				e->acceptAction();
			}
			else
			{
				e->ignore();
				e->acceptAction(false);
				if(currentThemeItem_)
				{
					unselectAllItems();
					currentThemeItem_->parent()->setSelected(true);
					currentThemeItem_->parent()->repaint();
					currentThemeItem_->setSelected(true);
					repaint();
				}
			}
		}
    }
	else
	{
		e->ignore();
		e->acceptAction(false);
	}
}
예제 #5
0
void DirectoryView::contentsMousePressEvent( QMouseEvent* e )
{
    QListView::contentsMousePressEvent(e);
    QPoint p( contentsToViewport( e->pos() ) );
    QListViewItem *i = itemAt( p );
    if ( i ) {
        // if the user clicked into the root decoration of the item, don't try to start a drag!
        if ( p.x() > header()->cellPos( header()->mapToActual( 0 ) ) +
             treeStepSize() * ( i->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ||
             p.x() < header()->cellPos( header()->mapToActual( 0 ) ) ) {
            presspos = e->pos();
            mousePressed = TRUE;
        }
    }
}
toTreeWidgetItem *toListView::printPage(TOPrinter *printer, QPainter *painter, toTreeWidgetItem *top, int &column, int &level, int pageNo, bool paint)
{
    Q3PaintDeviceMetrics wmetr(this);
    Q3PaintDeviceMetrics metrics(printer);

    double wpscalex = (double(metrics.width()) * wmetr.widthMM() / metrics.widthMM() / wmetr.width());
    double wpscaley = (double(metrics.height()) * wmetr.heightMM() / metrics.heightMM() / wmetr.height());

    painter->save();
    QFont font = painter->font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    painter->scale(wpscalex, wpscaley);

    double mwidth = metrics.width() / wpscalex;
    double mheight = metrics.height() / wpscaley;
    double x = 0;
    if (paint)
    {
        QString numPage(tr("Page: %1").arg(pageNo));
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignRight | Qt::AlignVCenter,
                          numPage);
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignHCenter | Qt::AlignVCenter,
                          middleString());
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter,
                          sqlName());
        painter->drawLine(0, header()->height() - 1, int(mwidth), header()->height() - 1);
    }
    font = toListView::font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    for (int i = column; i < columns(); i++)
    {
        double width = columnWidth(i);
        if (width + x >= mwidth)
        {
            if (i == column)
                width = mwidth - x - 1;
            else
                break;
        }
        if (paint)
            painter->drawText(int(x), 0, int(width),
                              header()->height(),
                              Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter, header()->label(i));
        x += width;
    }
    if (paint)
        painter->translate(0, header()->height());

    double y = (header()->height() + 1) + header()->height();
    int curLevel = level;
    int tree = rootIsDecorated() ? treeStepSize() : 0;
    int newCol = -1;
    toTreeWidgetItem *item = top;
    while (item && (y < mheight || item == top))
    {
        if (column == 0)
            x = curLevel;
        else
            x = 0;
        painter->translate(x, 0);
        for (int i = column; i < columns(); i++)
        {
            double width = columnWidth(i);
            if (width + x >= mwidth)
            {
                if (i == column)
                    width = mwidth - x - 1;
                else
                {
                    newCol = i;
                    break;
                }
            }
            if (i == 0)
                width -= curLevel;
            if (paint)
            {
                item->setSelected(false);
                item->paintCell(painter, qApp->palette().active(), i, int(width), columnAlignment(i));
                painter->translate(width, 0);
            }
            x += width;
        }
        if (paint)
            painter->translate(-x, item->height());
        y += item->height();
        if (item->firstChild())
        {
            item = item->firstChild();
            curLevel += tree;
        }
        else if (item->nextSibling())
            item = item->nextSibling();
        else
        {
            do
            {
                item = item->parent();
                curLevel -= tree;
            }
            while (item && !item->nextSibling());
            if (item)
                item = item->nextSibling();
        }
    }
    if (paint)
        painter->drawLine(0, 0, int(mwidth), 0);
    painter->restore();
    if (newCol >= 0)
    {
        column = newCol;
        return top;
    }
    column = 0;
    level = curLevel;
    return item;
}
void TeQtViewsListView::contentsMousePressEvent(QMouseEvent *e)
{
	rightMouseWasClicked_ = false;;
	if (e->button() == RightButton)
	{
		rightMouseWasClicked_ = true;
		popupMenu_->move(e->globalPos().x(), e->globalPos().y());
	}
	else if (e->button() == LeftButton)
	{
		QPoint p( contentsToViewport( e->pos() ) );
		pressedPosition_ = p;
		TeQtCheckListItem *item = (TeQtCheckListItem*)itemAt(p);
		if (item != 0)
		{
			if(item->getType() == TeQtCheckListItem::THEME)
			{
				// don?t drag, if the user clicked into the root decoration of the item
				int x = p.x();
				int len = treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)) + itemMargin();
				if (x > len)
//				if (p.x() > treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)) + itemMargin())
				{
					pressedThemeItem_ = (TeQtThemeItem*)item;
					themeOpen_ = isOpen(item);
				}
	
				// Item was pressed inside the visibility box
				if (x > len && x < len + 10)
				{
					if (e->state() & Qt::ShiftButton)
					{
						if (refThemeItemForVis_ == 0)
							refThemeItemForVis_ = (TeQtThemeItem*)item;
						else
						{
							TeQtThemeItem *themeItem = (TeQtThemeItem*)item;
							if ((themeItem == refThemeItemForVis_) ||
								(themeItem->parent() != refThemeItemForVis_->parent()))
								return;

							list<TeQtCheckListItem*> themeItemList;
							list<TeQtCheckListItem*>::iterator it;
							// find if the item pressed is below the reference item
							TeQtCheckListItem *itemBelow = (TeQtCheckListItem*)refThemeItemForVis_->itemBelow();
							while((itemBelow != 0) && (itemBelow->getType() == TeQtCheckListItem::THEME))
							{
								themeItemList.push_back(itemBelow);
								if (itemBelow == themeItem)
								{
									for (it = themeItemList.begin(); it != themeItemList.end(); ++it)
									{
										TeQtCheckListItem *thItem = *it;
										bool visible = refThemeItemForVis_->isOn();
										setOn(thItem, visible);
									}
									refThemeItemForVis_ = 0;
									return;
								}
								itemBelow = (TeQtCheckListItem*)itemBelow->itemBelow();
							}

							// find if the item pressed is above the reference item
							themeItemList.clear();
							TeQtCheckListItem *itemAbove = (TeQtCheckListItem*)refThemeItemForVis_->itemAbove();
							while((itemAbove != 0) && (itemAbove->getType() == TeQtCheckListItem::THEME))
							{
								themeItemList.push_back(itemAbove);
								if (itemAbove == themeItem)
								{
									for (it = themeItemList.begin(); it != themeItemList.end(); ++it)
									{
										TeQtCheckListItem* thItem = *it;
										bool visible = refThemeItemForVis_->isOn();
										setOn(thItem, visible);
									}
									refThemeItemForVis_ = 0;
									return;
								}
								itemAbove = (TeQtCheckListItem*)itemAbove->itemAbove();
							}
						}
					}
					else
						refThemeItemForVis_ = 0;
				}
			}
			else
			{
				item->setSelected(false);
				item->repaint();
				pressedThemeItem_ = 0;
			}
			leftButtonPressed_ = true;
		}
	}

	QListView::contentsMousePressEvent(e);
}