Commit e6f84716 authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

PDF view performance:multiple pages selection

parent 896383fd
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QString> #include <QString>
#include <QCursor> #include <QCursor>
#include "UBThumbnailWidget.h" #include "UBThumbnailWidget.h"
#include "UBRubberBand.h" #include "UBRubberBand.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBThumbnailWidget::UBThumbnailWidget(QWidget* parent) UBThumbnailWidget::UBThumbnailWidget(QWidget* parent)
: QGraphicsView(parent) : QGraphicsView(parent)
, mThumbnailWidth(UBSettings::defaultThumbnailWidth) , mThumbnailWidth(UBSettings::defaultThumbnailWidth)
, mSpacing(UBSettings::thumbnailSpacing) , mSpacing(UBSettings::thumbnailSpacing)
, mLastSelectedThumbnail(0) , mLastSelectedThumbnail(0)
, mSelectionSpan(0) , mSelectionSpan(0)
, mLassoRectItem(0) , mLassoRectItem(0)
{ {
// By default, the drag is possible // By default, the drag is possible
bCanDrag = true; bCanDrag = true;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
setFrameShape(QFrame::NoFrame); setFrameShape(QFrame::NoFrame);
setScene(&mThumbnailsScene); setScene(&mThumbnailsScene);
setAlignment(Qt::AlignLeft | Qt::AlignTop); setAlignment(Qt::AlignLeft | Qt::AlignTop);
connect(&mThumbnailsScene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged())); connect(&mThumbnailsScene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged()));
} }
UBThumbnailWidget::~UBThumbnailWidget() UBThumbnailWidget::~UBThumbnailWidget()
{ {
disconnect(&mThumbnailsScene, SIGNAL(selectionChanged())); disconnect(&mThumbnailsScene, SIGNAL(selectionChanged()));
} }
void UBThumbnailWidget::setThumbnailWidth(qreal pThumbnailWidth) void UBThumbnailWidget::setThumbnailWidth(qreal pThumbnailWidth)
{ {
mThumbnailWidth = pThumbnailWidth; mThumbnailWidth = pThumbnailWidth;
refreshScene(); refreshScene();
} }
void UBThumbnailWidget::setSpacing(qreal pSpacing) void UBThumbnailWidget::setSpacing(qreal pSpacing)
{ {
mSpacing = pSpacing; mSpacing = pSpacing;
refreshScene(); refreshScene();
} }
void UBThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems void UBThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems
, const QList<QUrl>& pItemsPaths , const QList<QUrl>& pItemsPaths
, const QStringList pLabels , const QStringList pLabels
, const QString& pMimeType) , const QString& pMimeType)
{ {
mGraphicItems = pGraphicsItems; mGraphicItems = pGraphicsItems;
mItemsPaths = pItemsPaths; mItemsPaths = pItemsPaths;
mMimeType = pMimeType; mMimeType = pMimeType;
mLabels = pLabels; mLabels = pLabels;
foreach(QGraphicsItem* it, mThumbnailsScene.items()) foreach(QGraphicsItem* it, mThumbnailsScene.items())
{ {
mThumbnailsScene.removeItem(it, true); mThumbnailsScene.removeItem(it, true);
} }
// set lasso to 0 as it has been cleared as well // set lasso to 0 as it has been cleared as well
mLassoRectItem = 0; mLassoRectItem = 0;
foreach (QGraphicsItem* item, pGraphicsItems) foreach (QGraphicsItem* item, pGraphicsItems)
{ {
if (item->scene() != &mThumbnailsScene) if (item->scene() != &mThumbnailsScene)
{ {
mThumbnailsScene.addItem(item); mThumbnailsScene.addItem(item);
} }
} }
mLabelsItems.clear(); mLabelsItems.clear();
foreach (const QString label, pLabels) foreach (const QString label, pLabels)
{ {
QFontMetrics fm(font()); QFontMetrics fm(font());
UBThumbnailTextItem *labelItem = UBThumbnailTextItem *labelItem =
new UBThumbnailTextItem(label); // deleted while replace or by the scene destruction new UBThumbnailTextItem(label); // deleted while replace or by the scene destruction
mThumbnailsScene.addItem(labelItem); mThumbnailsScene.addItem(labelItem);
mLabelsItems << labelItem; mLabelsItems << labelItem;
} }
refreshScene(); refreshScene();
mLastSelectedThumbnail = 0; mLastSelectedThumbnail = 0;
} }
void UBThumbnailWidget::refreshScene() void UBThumbnailWidget::refreshScene()
{ {
int nbColumns = (geometry().width() - mSpacing) / (mThumbnailWidth + mSpacing); int nbColumns = (geometry().width() - mSpacing) / (mThumbnailWidth + mSpacing);
int labelSpacing = 0; int labelSpacing = 0;
if (mLabelsItems.size() > 0) if (mLabelsItems.size() > 0)
{ {
QFontMetrics fm(mLabelsItems.at(0)->font()); QFontMetrics fm(mLabelsItems.at(0)->font());
labelSpacing = UBSettings::thumbnailSpacing + fm.height(); // TODO UB 4.x where is 20 from ??? configure ?? compute based on mSpacing ?? JBA Is it the font height? labelSpacing = UBSettings::thumbnailSpacing + fm.height(); // TODO UB 4.x where is 20 from ??? configure ?? compute based on mSpacing ?? JBA Is it the font height?
} }
nbColumns = qMax(nbColumns, 1); nbColumns = qMax(nbColumns, 1);
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio; qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
for (int i = 0; i < mGraphicItems.size(); i++) for (int i = 0; i < mGraphicItems.size(); i++)
{ {
QGraphicsItem* item = mGraphicItems.at(i); QGraphicsItem* item = mGraphicItems.at(i);
qreal scaleWidth = mThumbnailWidth / item->boundingRect().width(); qreal scaleWidth = mThumbnailWidth / item->boundingRect().width();
qreal scaleHeight = thumbnailHeight / item->boundingRect().height(); qreal scaleHeight = thumbnailHeight / item->boundingRect().height();
qreal scaleFactor = qMin(scaleWidth, scaleHeight); qreal scaleFactor = qMin(scaleWidth, scaleHeight);
//bitmap should not be stretched //bitmap should not be stretched
UBThumbnail* pix = dynamic_cast<UBThumbnail*>(item); UBThumbnail* pix = dynamic_cast<UBThumbnail*>(item);
if (pix) if (pix)
scaleFactor = qMin(scaleFactor, 1.0); scaleFactor = qMin(scaleFactor, 1.0);
QTransform transform; QTransform transform;
transform.scale(scaleFactor, scaleFactor); transform.scale(scaleFactor, scaleFactor);
item->setTransform(transform); item->setTransform(transform);
item->setFlag(QGraphicsItem::ItemIsSelectable, true); item->setFlag(QGraphicsItem::ItemIsSelectable, true);
int columnIndex = i % nbColumns; int columnIndex = i % nbColumns;
int rowIndex = i / nbColumns; int rowIndex = i / nbColumns;
if (pix) if (pix)
{ {
pix->setColumn(columnIndex); pix->setColumn(columnIndex);
pix->setRow(rowIndex); pix->setRow(rowIndex);
} }
int w = item->boundingRect().width(); int w = item->boundingRect().width();
int h = item->boundingRect().height(); int h = item->boundingRect().height();
QPointF pos( QPointF pos(
mSpacing + (mThumbnailWidth - w * scaleFactor) / 2 + columnIndex * (mThumbnailWidth + mSpacing), mSpacing + (mThumbnailWidth - w * scaleFactor) / 2 + columnIndex * (mThumbnailWidth + mSpacing),
mSpacing + rowIndex * (thumbnailHeight + mSpacing + labelSpacing) + (thumbnailHeight - h * scaleFactor) / 2); mSpacing + rowIndex * (thumbnailHeight + mSpacing + labelSpacing) + (thumbnailHeight - h * scaleFactor) / 2);
item->setPos(pos); item->setPos(pos);
if (mLabelsItems.size() > i) if (mLabelsItems.size() > i)
{ {
QFontMetrics fm(mLabelsItems.at(i)->font(), this); QFontMetrics fm(mLabelsItems.at(i)->font(), this);
QString elidedText = fm.elidedText(mLabels.at(i), Qt::ElideRight, mThumbnailWidth); QString elidedText = fm.elidedText(mLabels.at(i), Qt::ElideRight, mThumbnailWidth);
mLabelsItems.at(i)->setPlainText(elidedText); mLabelsItems.at(i)->setPlainText(elidedText);
mLabelsItems.at(i)->setWidth(fm.width(elidedText) + 2 * mLabelsItems.at(i)->document()->documentMargin()); mLabelsItems.at(i)->setWidth(fm.width(elidedText) + 2 * mLabelsItems.at(i)->document()->documentMargin());
pos.setY(pos.y() + (thumbnailHeight + h * scaleFactor) / 2 + 5); pos.setY(pos.y() + (thumbnailHeight + h * scaleFactor) / 2 + 5);
qreal labelWidth = fm.width(elidedText); qreal labelWidth = fm.width(elidedText);
pos.setX(mSpacing + (mThumbnailWidth - labelWidth) / 2 + columnIndex * (mThumbnailWidth + mSpacing)); pos.setX(mSpacing + (mThumbnailWidth - labelWidth) / 2 + columnIndex * (mThumbnailWidth + mSpacing));
mLabelsItems.at(i)->setPos(pos); mLabelsItems.at(i)->setPos(pos);
} }
} }
QScrollBar *vertScrollBar = verticalScrollBar(); QScrollBar *vertScrollBar = verticalScrollBar();
int scrollBarThickness = 0; int scrollBarThickness = 0;
if (vertScrollBar && vertScrollBar->isVisible()) if (vertScrollBar && vertScrollBar->isVisible())
scrollBarThickness = vertScrollBar->width(); scrollBarThickness = vertScrollBar->width();
setSceneRect(0, 0, setSceneRect(0, 0,
geometry().width() - scrollBarThickness, geometry().width() - scrollBarThickness,
mSpacing + ((((mGraphicItems.size() - 1) / nbColumns) + 1) * (thumbnailHeight + mSpacing + labelSpacing))); mSpacing + ((((mGraphicItems.size() - 1) / nbColumns) + 1) * (thumbnailHeight + mSpacing + labelSpacing)));
} }
QList<QGraphicsItem*> UBThumbnailWidget::selectedItems() QList<QGraphicsItem*> UBThumbnailWidget::selectedItems()
{ {
QList<QGraphicsItem*> sortedSelectedItems = mThumbnailsScene.selectedItems(); QList<QGraphicsItem*> sortedSelectedItems = mThumbnailsScene.selectedItems();
qSort(sortedSelectedItems.begin(), sortedSelectedItems.end(), thumbnailLessThan); qSort(sortedSelectedItems.begin(), sortedSelectedItems.end(), thumbnailLessThan);
return sortedSelectedItems; return sortedSelectedItems;
} }
void UBThumbnailWidget::mousePressEvent(QMouseEvent *event) void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
{ {
mClickTime = QTime::currentTime(); mClickTime = QTime::currentTime();
mMousePressPos = event->pos(); mMousePressPos = event->pos();
mMousePressScenePos = mapToScene(mMousePressPos); mMousePressScenePos = mapToScene(mMousePressPos);
QGraphicsItem* underlyingItem = itemAt(mMousePressPos); QGraphicsItem* underlyingItem = itemAt(mMousePressPos);
UBThumbnail *previousSelectedThumbnail = mLastSelectedThumbnail; UBThumbnail *previousSelectedThumbnail = mLastSelectedThumbnail;
if (!dynamic_cast<UBThumbnail*>(underlyingItem)) if (!dynamic_cast<UBThumbnail*>(underlyingItem))
{ {
deleteLasso(); deleteLasso();
UBRubberBand rubberBand(QRubberBand::Rectangle); UBRubberBand rubberBand(QRubberBand::Rectangle);
QStyleOption option; QStyleOption option;
option.initFrom(&rubberBand); option.initFrom(&rubberBand);
mLassoRectItem = new QGraphicsRectItem(0, scene()); mLassoRectItem = new QGraphicsRectItem(0, scene());
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
// The following code must stay in synch with <Qt installation folder>\src\gui\styles\qmacstyle_mac.mm // The following code must stay in synch with <Qt installation folder>\src\gui\styles\qmacstyle_mac.mm
QColor strokeColor; QColor strokeColor;
strokeColor.setHsvF(0, 0, 0.86, 1.0); strokeColor.setHsvF(0, 0, 0.86, 1.0);
mLassoRectItem->setPen(QPen(strokeColor)); mLassoRectItem->setPen(QPen(strokeColor));
QColor fillColor(option.palette.color(QPalette::Disabled, QPalette::Highlight)); QColor fillColor(option.palette.color(QPalette::Disabled, QPalette::Highlight));
fillColor.setHsvF(0, 0, 0.53, 0.25); fillColor.setHsvF(0, 0, 0.53, 0.25);
mLassoRectItem->setBrush(fillColor); mLassoRectItem->setBrush(fillColor);
#else #else
// The following code must stay in synch with <Qt installation folder>\src\gui\styles\qwindowsxpstyle.cpp // The following code must stay in synch with <Qt installation folder>\src\gui\styles\qwindowsxpstyle.cpp
QColor highlight = option.palette.color(QPalette::Active, QPalette::Highlight); QColor highlight = option.palette.color(QPalette::Active, QPalette::Highlight);
mLassoRectItem->setPen(highlight.darker(120)); mLassoRectItem->setPen(highlight.darker(120));
QColor dimHighlight(qMin(highlight.red() / 2 + 110, 255), QColor dimHighlight(qMin(highlight.red() / 2 + 110, 255),
qMin(highlight.green() / 2 + 110, 255), qMin(highlight.green() / 2 + 110, 255),
qMin(highlight.blue() / 2 + 110, 255), qMin(highlight.blue() / 2 + 110, 255),
127); 127);
mLassoRectItem->setBrush(dimHighlight); mLassoRectItem->setBrush(dimHighlight);
#endif #endif
mLassoRectItem->setZValue(10000); mLassoRectItem->setZValue(10000);
mLassoRectItem->setRect(QRectF(mMousePressScenePos, QSizeF())); mLassoRectItem->setRect(QRectF(mMousePressScenePos, QSizeF()));
if (Qt::ControlModifier & event->modifiers() || Qt::ShiftModifier & event->modifiers()) if (Qt::ControlModifier & event->modifiers() || Qt::ShiftModifier & event->modifiers())
{ {
mSelectedThumbnailItems = selectedItems(); // mSelectedThumbnailItems = selectedItems().toSet();
return; return;
} }
mSelectedThumbnailItems.clear(); mSelectedThumbnailItems.clear();
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
} }
else if (Qt::ShiftModifier & event->modifiers()) else if (Qt::ShiftModifier & event->modifiers())
{ {
if (previousSelectedThumbnail) if (previousSelectedThumbnail)
{ {
QGraphicsItem* previousSelectedItem = dynamic_cast<QGraphicsItem*>(previousSelectedThumbnail); QGraphicsItem* previousSelectedItem = dynamic_cast<QGraphicsItem*>(previousSelectedThumbnail);
if (previousSelectedItem) if (previousSelectedItem)
{ {
int index1 = mGraphicItems.indexOf(previousSelectedItem); int index1 = mGraphicItems.indexOf(previousSelectedItem);
int index2 = mGraphicItems.indexOf(underlyingItem); int index2 = mGraphicItems.indexOf(underlyingItem);
if (-1 == index2) if (-1 == index2)
{ {
mSelectedThumbnailItems = selectedItems(); mSelectedThumbnailItems = selectedItems().toSet();
return; return;
} }
mSelectionSpan = index2 - index1; mSelectionSpan = index2 - index1;
selectItems(qMin(index1, index2), mSelectionSpan < 0 ? - mSelectionSpan + 1 : mSelectionSpan + 1); selectItems(qMin(index1, index2), mSelectionSpan < 0 ? - mSelectionSpan + 1 : mSelectionSpan + 1);
return; return;
} }
} }
} }
else else
{ {
mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(underlyingItem); mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(underlyingItem);
if (!underlyingItem->isSelected()) if (!underlyingItem->isSelected())
{ {
int index = mGraphicItems.indexOf(underlyingItem); int index = mGraphicItems.indexOf(underlyingItem);
selectItemAt(index, Qt::ControlModifier & event->modifiers()); selectItemAt(index, Qt::ControlModifier & event->modifiers());
} }
else else
{ {
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
} }
if (!mLastSelectedThumbnail && mGraphicItems.count() > 0) if (!mLastSelectedThumbnail && mGraphicItems.count() > 0)
mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.at(0)); mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.at(0));
mSelectionSpan = 0; mSelectionSpan = 0;
return; return;
} }
} }
void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event) void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
{ {
int distance = (mMousePressPos - event->pos()).manhattanLength(); int distance = (mMousePressPos - event->pos()).manhattanLength();
if (0 == (event->buttons() & Qt::LeftButton) || distance < QApplication::startDragDistance()) if (0 == (event->buttons() & Qt::LeftButton) || distance < QApplication::startDragDistance())
return; return;
if (mLassoRectItem) if (mLassoRectItem)
{ {
bSelectionInProgress = true; bSelectionInProgress = true;
QPointF currentScenePos = mapToScene(event->pos()); int incrementLassoMinWidth = 2;
QRectF lassoRect( QPointF currentScenePos = mapToScene(event->pos());
qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()), QRectF lassoRect(
qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(mMousePressScenePos.y() - currentScenePos.y())); qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()),
mLassoRectItem->setRect(lassoRect); qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(mMousePressScenePos.y() - currentScenePos.y()));
QRectF incrementXSelection(
QList<QGraphicsItem*> lassoSelectedItems = scene()->items(lassoRect, Qt::IntersectsItemBoundingRect); qMin(prevMoveMousePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()),
QList<QGraphicsItem*> lassoSelectedThumbnailItems; qAbs(prevMoveMousePos.x() - currentScenePos.x())+incrementLassoMinWidth, qAbs(mMousePressScenePos.y() - currentScenePos.y()));
foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedItems) QRectF incrementYSelection(
{ qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(prevMoveMousePos.y(), currentScenePos.y()),
UBThumbnail *thumbnailItem = dynamic_cast<UBThumbnail*>(lassoSelectedItem); qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(prevMoveMousePos.y() - currentScenePos.y())+incrementLassoMinWidth);
if (thumbnailItem)
lassoSelectedThumbnailItems.append(lassoSelectedItems); prevMoveMousePos = currentScenePos;
} mLassoRectItem->setRect(lassoRect);
unselectAll();
foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedThumbnailItems) QSet<QGraphicsItem*> incSelectedItems = scene()->items(incrementXSelection, Qt::IntersectsItemBoundingRect).toSet()
{ + scene()->items(incrementYSelection, Qt::IntersectsItemBoundingRect).toSet();
if (Qt::ControlModifier & event->modifiers())
{ mPreviouslyIncrementalSelectedItems = incSelectedItems;
if (!mSelectedThumbnailItems.contains(lassoSelectedItem)) QSet<QGraphicsItem*> lassoSelectedItems;
selectItemAt(mGraphicItems.indexOf(lassoSelectedItem), true); QSet<QGraphicsItem*> lassoSelectedThumbnailItems;
} foreach (QGraphicsItem *lassoSelectedItem, incSelectedItems)
else {
{ if (lassoSelectedItem)
selectItemAt(mGraphicItems.indexOf(lassoSelectedItem), true); {
} UBSceneThumbnailPixmap *thumbnailItem = dynamic_cast<UBSceneThumbnailPixmap*>(lassoSelectedItem);
}
if (Qt::ControlModifier & event->modifiers()) if (thumbnailItem)
{ {
foreach (QGraphicsItem *selectedItem, mSelectedThumbnailItems) lassoSelectedItem->setSelected(true);
{ lassoSelectedThumbnailItems += lassoSelectedItem;
if (!lassoSelectedThumbnailItems.contains(selectedItem)) }
selectItemAt(mGraphicItems.indexOf(selectedItem), true); }
} }
}
} QSet<QGraphicsItem*> toUnset;
else toUnset = mSelectedThumbnailItems - lassoSelectedThumbnailItems;
{ foreach(QGraphicsItem* item, toUnset)
bSelectionInProgress = false; {
if (0 == selectedItems().size()) item->setSelected(false);
return; }
if(bCanDrag)
{ mSelectedThumbnailItems += lassoSelectedItems;
QDrag *drag = new QDrag(this); // foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedThumbnailItems)
QMimeData *mime = new QMimeData(); {
if (mMimeType.length() > 0) }
mime->setData(mMimeType, QByteArray()); // trick the d&d system to register our own mime type if (Qt::ControlModifier & event->modifiers())
{
drag->setMimeData(mime); for (int i = 0; i < mSelectedThumbnailItems.count()-1; i++)
{
QList<QUrl> qlElements; mSelectedThumbnailItems.values().at(i)->setSelected(true);
}
foreach (QGraphicsItem* item, selectedItems()) // foreach (QGraphicsItem *selectedItem, mSelectedThumbnailItems)
{ {
if (mGraphicItems.contains(item)) // selectedItem->setSelected(true);
{ }
if (mGraphicItems.indexOf(item) <= mItemsPaths.size()){ }
qlElements << mItemsPaths.at(mGraphicItems.indexOf(item)); }
} else
} {
} bSelectionInProgress = false;
if (0 == selectedItems().size())
if (qlElements.size() > 0){ return;
mime->setUrls(qlElements);
drag->setMimeData(mime); if(bCanDrag)
drag->exec(Qt::CopyAction); {
} QDrag *drag = new QDrag(this);
} QMimeData *mime = new QMimeData();
}
if (mMimeType.length() > 0)
QGraphicsView::mouseMoveEvent(event); mime->setData(mMimeType, QByteArray()); // trick the d&d system to register our own mime type
}
drag->setMimeData(mime);
void UBThumbnailWidget::mouseReleaseEvent(QMouseEvent *event) QList<QUrl> qlElements;
{
int elapsedTimeSincePress = mClickTime.elapsed(); foreach (QGraphicsItem* item, selectedItems())
deleteLasso(); {
QGraphicsView::mouseReleaseEvent(event); if (mGraphicItems.contains(item))
{
if(elapsedTimeSincePress < STARTDRAGTIME) { if (mGraphicItems.indexOf(item) <= mItemsPaths.size()){
emit mouseClick(itemAt(event->pos()), 0); qlElements << mItemsPaths.at(mGraphicItems.indexOf(item));
} }
} }
}
void UBThumbnailWidget::keyPressEvent(QKeyEvent *event) if (qlElements.size() > 0){
{ mime->setUrls(qlElements);
if (mLastSelectedThumbnail) drag->setMimeData(mime);
{ drag->exec(Qt::CopyAction);
QGraphicsItem *lastSelectedGraphicsItem = dynamic_cast<QGraphicsItem*>(mLastSelectedThumbnail); }
if (!lastSelectedGraphicsItem) return; }
int startSelectionIndex = mGraphicItems.indexOf(lastSelectedGraphicsItem); }
int previousSelectedThumbnailIndex = startSelectionIndex + mSelectionSpan;
QGraphicsView::mouseMoveEvent(event);
switch (event->key()) }
{
case Qt::Key_Down:
case Qt::Key_Up: void UBThumbnailWidget::mouseReleaseEvent(QMouseEvent *event)
{ {
if (rowCount() <= 1) break; int elapsedTimeSincePress = mClickTime.elapsed();
if (Qt::ShiftModifier & event->modifiers()) deleteLasso();
{ QGraphicsView::mouseReleaseEvent(event);
int endSelectionIndex;
if (Qt::Key_Down == event->key()) if(elapsedTimeSincePress < STARTDRAGTIME) {
{ emit mouseClick(itemAt(event->pos()), 0);
endSelectionIndex = previousSelectedThumbnailIndex + columnCount(); }
if (endSelectionIndex >= mGraphicItems.count()) break; }
}
else
{ void UBThumbnailWidget::keyPressEvent(QKeyEvent *event)
endSelectionIndex = previousSelectedThumbnailIndex - columnCount(); {
if (endSelectionIndex < 0) break; if (mLastSelectedThumbnail)
} {
QGraphicsItem *lastSelectedGraphicsItem = dynamic_cast<QGraphicsItem*>(mLastSelectedThumbnail);
int startIndex = startSelectionIndex < endSelectionIndex ? startSelectionIndex : endSelectionIndex; if (!lastSelectedGraphicsItem) return;
int count = startSelectionIndex < endSelectionIndex ? endSelectionIndex - startSelectionIndex + 1 : startSelectionIndex - endSelectionIndex + 1; int startSelectionIndex = mGraphicItems.indexOf(lastSelectedGraphicsItem);
mSelectionSpan = startSelectionIndex < endSelectionIndex ? (count - 1) : - (count - 1); int previousSelectedThumbnailIndex = startSelectionIndex + mSelectionSpan;
selectItems(startIndex, count);
} switch (event->key())
else {
{ case Qt::Key_Down:
int toSelectIndex; case Qt::Key_Up:
if (Qt::Key_Down == event->key()) {
{ if (rowCount() <= 1) break;
toSelectIndex = previousSelectedThumbnailIndex + columnCount(); if (Qt::ShiftModifier & event->modifiers())
if (toSelectIndex >= mGraphicItems.count()) break; {
} int endSelectionIndex;
else if (Qt::Key_Down == event->key())
{ {
toSelectIndex = previousSelectedThumbnailIndex - columnCount(); endSelectionIndex = previousSelectedThumbnailIndex + columnCount();
if (toSelectIndex < 0) break; if (endSelectionIndex >= mGraphicItems.count()) break;
} }
else
selectItemAt(toSelectIndex, Qt::ControlModifier & event->modifiers()); {
mSelectionSpan = 0; endSelectionIndex = previousSelectedThumbnailIndex - columnCount();
} if (endSelectionIndex < 0) break;
} }
break;
int startIndex = startSelectionIndex < endSelectionIndex ? startSelectionIndex : endSelectionIndex;
case Qt::Key_Left: int count = startSelectionIndex < endSelectionIndex ? endSelectionIndex - startSelectionIndex + 1 : startSelectionIndex - endSelectionIndex + 1;
case Qt::Key_Right: mSelectionSpan = startSelectionIndex < endSelectionIndex ? (count - 1) : - (count - 1);
{ selectItems(startIndex, count);
QGraphicsItem *previousSelectedItem = mGraphicItems.at(previousSelectedThumbnailIndex); }
UBThumbnail *previousSelectedThumbnail = dynamic_cast<UBThumbnail*>(previousSelectedItem); else
if (!previousSelectedThumbnail) break; {
int toSelectIndex;
if (Qt::Key_Left == event->key()) if (Qt::Key_Down == event->key())
{ {
if (0 == previousSelectedThumbnail->column()) break; toSelectIndex = previousSelectedThumbnailIndex + columnCount();
} if (toSelectIndex >= mGraphicItems.count()) break;
else }
{ else
if (previousSelectedThumbnail->column() == columnCount() - 1 || {
previousSelectedThumbnailIndex == mGraphicItems.count() - 1) break; toSelectIndex = previousSelectedThumbnailIndex - columnCount();
} if (toSelectIndex < 0) break;
}
if (Qt::ShiftModifier & event->modifiers())
{ selectItemAt(toSelectIndex, Qt::ControlModifier & event->modifiers());
int endSelectionIndex; mSelectionSpan = 0;
if (Qt::Key_Left == event->key()) }
{ }
endSelectionIndex = previousSelectedThumbnailIndex - 1; break;
if (endSelectionIndex < 0) break;
} case Qt::Key_Left:
else case Qt::Key_Right:
{ {
endSelectionIndex = previousSelectedThumbnailIndex + 1; QGraphicsItem *previousSelectedItem = mGraphicItems.at(previousSelectedThumbnailIndex);
if (endSelectionIndex >= mGraphicItems.count()) break; UBThumbnail *previousSelectedThumbnail = dynamic_cast<UBThumbnail*>(previousSelectedItem);
} if (!previousSelectedThumbnail) break;
int startIndex = startSelectionIndex < endSelectionIndex ? startSelectionIndex : endSelectionIndex; if (Qt::Key_Left == event->key())
int count = startSelectionIndex < endSelectionIndex ? endSelectionIndex - startSelectionIndex + 1 : startSelectionIndex - endSelectionIndex + 1; {
mSelectionSpan = startSelectionIndex < endSelectionIndex ? (count - 1) : - (count - 1); if (0 == previousSelectedThumbnail->column()) break;
selectItems(startIndex, count); }
} else
else {
{ if (previousSelectedThumbnail->column() == columnCount() - 1 ||
if (Qt::Key_Left == event->key()) previousSelectedThumbnailIndex == mGraphicItems.count() - 1) break;
selectItemAt(previousSelectedThumbnailIndex - 1, Qt::ControlModifier & event->modifiers()); }
else
selectItemAt(previousSelectedThumbnailIndex + 1, Qt::ControlModifier & event->modifiers()); if (Qt::ShiftModifier & event->modifiers())
{
mSelectionSpan = 0; int endSelectionIndex;
} if (Qt::Key_Left == event->key())
} {
break; endSelectionIndex = previousSelectedThumbnailIndex - 1;
if (endSelectionIndex < 0) break;
case Qt::Key_Home: }
{ else
if (Qt::ShiftModifier & event->modifiers()) {
{ endSelectionIndex = previousSelectedThumbnailIndex + 1;
mSelectionSpan = - startSelectionIndex; if (endSelectionIndex >= mGraphicItems.count()) break;
selectItems(0, startSelectionIndex + 1); }
}
else int startIndex = startSelectionIndex < endSelectionIndex ? startSelectionIndex : endSelectionIndex;
{ int count = startSelectionIndex < endSelectionIndex ? endSelectionIndex - startSelectionIndex + 1 : startSelectionIndex - endSelectionIndex + 1;
selectItemAt(0, Qt::ControlModifier & event->modifiers()); mSelectionSpan = startSelectionIndex < endSelectionIndex ? (count - 1) : - (count - 1);
mSelectionSpan = 0; selectItems(startIndex, count);
} }
} else
break; {
if (Qt::Key_Left == event->key())
case Qt::Key_End: selectItemAt(previousSelectedThumbnailIndex - 1, Qt::ControlModifier & event->modifiers());
{ else
if (Qt::ShiftModifier & event->modifiers()) selectItemAt(previousSelectedThumbnailIndex + 1, Qt::ControlModifier & event->modifiers());
{
mSelectionSpan = mGraphicItems.count() - startSelectionIndex - 1; mSelectionSpan = 0;
selectItems(startSelectionIndex, mSelectionSpan + 1); }
} }
else break;
{
selectItemAt(mGraphicItems.count() - 1, Qt::ControlModifier & event->modifiers()); case Qt::Key_Home:
mSelectionSpan = 0; {
} if (Qt::ShiftModifier & event->modifiers())
} {
break; mSelectionSpan = - startSelectionIndex;
case Qt::Key_A: selectItems(0, startSelectionIndex + 1);
{ }
if (Qt::ControlModifier & event->modifiers()) else
selectAll(); {
} selectItemAt(0, Qt::ControlModifier & event->modifiers());
break; mSelectionSpan = 0;
} }
} }
QGraphicsView::keyPressEvent(event); break;
}
case Qt::Key_End:
{
void UBThumbnailWidget::focusInEvent(QFocusEvent *event) if (Qt::ShiftModifier & event->modifiers())
{ {
Q_UNUSED(event); mSelectionSpan = mGraphicItems.count() - startSelectionIndex - 1;
selectItems(startSelectionIndex, mSelectionSpan + 1);
if (0 == selectedItems().count() && mGraphicItems.count() > 0 && Qt::TabFocusReason == event->reason()) }
{ else
selectItemAt(0); {
mSelectionSpan = 0; selectItemAt(mGraphicItems.count() - 1, Qt::ControlModifier & event->modifiers());
} mSelectionSpan = 0;
} }
}
break;
void UBThumbnailWidget::resizeEvent(QResizeEvent *event) case Qt::Key_A:
{ {
Q_UNUSED(event); if (Qt::ControlModifier & event->modifiers())
selectAll();
refreshScene(); }
break;
emit resized(); }
} }
QGraphicsView::keyPressEvent(event);
}
void UBThumbnailWidget::sceneSelectionChanged()
{
emit selectionChanged(); void UBThumbnailWidget::focusInEvent(QFocusEvent *event)
} {
Q_UNUSED(event);
void UBThumbnailWidget::selectItemAt(int pIndex, bool extend) if (0 == selectedItems().count() && mGraphicItems.count() > 0 && Qt::TabFocusReason == event->reason())
{ {
QGraphicsItem* itemToSelect = 0; selectItemAt(0);
mSelectionSpan = 0;
if (pIndex >= 0 && pIndex < mGraphicItems.size()) }
itemToSelect = mGraphicItems.at(pIndex); }
foreach (QGraphicsItem* item, items())
{ void UBThumbnailWidget::resizeEvent(QResizeEvent *event)
if (item == itemToSelect) {
{ Q_UNUSED(event);
mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(item);
item->setSelected(true); refreshScene();
ensureVisible(item);
} emit resized();
else if (!extend) }
{
item->setSelected(false);
} void UBThumbnailWidget::sceneSelectionChanged()
} {
} emit selectionChanged();
}
void UBThumbnailWidget::unselectItemAt(int pIndex)
{
if (pIndex >= 0 && pIndex < mGraphicItems.size()) void UBThumbnailWidget::selectItemAt(int pIndex, bool extend)
{ {
QGraphicsItem *itemToUnselect = mGraphicItems.at(pIndex); QGraphicsItem* itemToSelect = 0;
itemToUnselect->setSelected(false);
} if (pIndex >= 0 && pIndex < mGraphicItems.size())
} itemToSelect = mGraphicItems.at(pIndex);
foreach (QGraphicsItem* item, items())
void UBThumbnailWidget::selectItems(int startIndex, int count) {
{ if (item == itemToSelect)
for (int i = 0; i < mGraphicItems.count(); i++) {
{ mLastSelectedThumbnail = dynamic_cast<UBThumbnail*>(item);
mGraphicItems.at(i)->setSelected(i >= startIndex && i < startIndex + count); item->setSelected(true);
} ensureVisible(item);
} }
else if (!extend)
{
void UBThumbnailWidget::selectAll() item->setSelected(false);
{ }
foreach (QGraphicsItem* item, mGraphicItems) }
{ }
item->setSelected(true);
} void UBThumbnailWidget::unselectItemAt(int pIndex)
} {
if (pIndex >= 0 && pIndex < mGraphicItems.size())
void UBThumbnailWidget::unselectAll() {
{ QGraphicsItem *itemToUnselect = mGraphicItems.at(pIndex);
foreach (QGraphicsItem* item, mGraphicItems) itemToUnselect->setSelected(false);
{ }
item->setSelected(false); }
}
}
void UBThumbnailWidget::selectItems(int startIndex, int count)
int UBThumbnailWidget::rowCount() const {
{ for (int i = 0; i < mGraphicItems.count(); i++)
UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last()); {
return lastThumbnail ? lastThumbnail->row() + 1 : 0; mGraphicItems.at(i)->setSelected(i >= startIndex && i < startIndex + count);
} }
}
int UBThumbnailWidget::columnCount() const
{
UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last()); void UBThumbnailWidget::selectAll()
if (!lastThumbnail) return 0; {
int lastRow = lastThumbnail->row(); foreach (QGraphicsItem* item, mGraphicItems)
int lastColumn = lastThumbnail->column(); {
return lastRow > 0 ? (mGraphicItems.count() - lastColumn - 1) / lastRow : mGraphicItems.count(); item->setSelected(true);
} }
}
void UBThumbnailWidget::mouseDoubleClickEvent(QMouseEvent * event) int UBThumbnailWidget::rowCount() const
{ {
QGraphicsItem* item = itemAt(event->pos()); UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last());
return lastThumbnail ? lastThumbnail->row() + 1 : 0;
if (item) }
{
int index = mGraphicItems.indexOf(item); int UBThumbnailWidget::columnCount() const
emit mouseDoubleClick(item, index); {
} UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last());
} if (!lastThumbnail) return 0;
int lastRow = lastThumbnail->row();
int lastColumn = lastThumbnail->column();
bool UBThumbnailWidget::thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2) return lastRow > 0 ? (mGraphicItems.count() - lastColumn - 1) / lastRow : mGraphicItems.count();
{ }
UBThumbnail *thumbnail1 = dynamic_cast<UBThumbnail*>(item1);
UBThumbnail *thumbnail2 = dynamic_cast<UBThumbnail*>(item2);
if (thumbnail1 && thumbnail2) void UBThumbnailWidget::mouseDoubleClickEvent(QMouseEvent * event)
{ {
if (thumbnail1->row() != thumbnail2->row()) QGraphicsItem* item = itemAt(event->pos());
return thumbnail1->row() < thumbnail2->row();
else if (item)
return thumbnail1->column() < thumbnail2->column(); {
} int index = mGraphicItems.indexOf(item);
return false; emit mouseDoubleClick(item, index);
} }
}
void UBThumbnailWidget::deleteLasso()
{
if (mLassoRectItem && scene()) bool UBThumbnailWidget::thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2)
{ {
scene()->removeItem(mLassoRectItem); UBThumbnail *thumbnail1 = dynamic_cast<UBThumbnail*>(item1);
delete mLassoRectItem; UBThumbnail *thumbnail2 = dynamic_cast<UBThumbnail*>(item2);
mLassoRectItem = 0; if (thumbnail1 && thumbnail2)
} {
} if (thumbnail1->row() != thumbnail2->row())
return thumbnail1->row() < thumbnail2->row();
else
UBThumbnail::UBThumbnail() return thumbnail1->column() < thumbnail2->column();
: mAddedToScene(false) }
{ return false;
mSelectionItem = new QGraphicsRectItem(0, 0, 0, 0); }
mSelectionItem->setPen(QPen(UBSettings::treeViewBackgroundColor, 8));
// TODO UB 4.x fix nasty dependencies : 8 is a bit less than half of UBThumbnailWidget.mSpacing void UBThumbnailWidget::deleteLasso()
} {
if (mLassoRectItem && scene())
UBThumbnail::~UBThumbnail() {
{ scene()->removeItem(mLassoRectItem);
if (mSelectionItem && !mAddedToScene) delete mLassoRectItem;
delete mSelectionItem; mLassoRectItem = 0;
} }
}
UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
: UBSceneThumbnailPixmap(pix, proxy, pSceneIndex) UBThumbnail::UBThumbnail()
, bButtonsVisible(false) : mAddedToScene(false)
, bCanDelete(false) {
, bCanMoveUp(false) mSelectionItem = new QGraphicsRectItem(0, 0, 0, 0);
, bCanMoveDown(false) mSelectionItem->setPen(QPen(UBSettings::treeViewBackgroundColor, 8));
{ // TODO UB 4.x fix nasty dependencies : 8 is a bit less than half of UBThumbnailWidget.mSpacing
setAcceptsHoverEvents(true); }
setFlag(QGraphicsItem::ItemIsSelectable, true);
} UBThumbnail::~UBThumbnail()
{
UBSceneThumbnailNavigPixmap::~UBSceneThumbnailNavigPixmap() if (mSelectionItem && !mAddedToScene)
{ delete mSelectionItem;
}
}
void UBSceneThumbnailNavigPixmap::hoverEnterEvent(QGraphicsSceneHoverEvent *event) UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
{ : UBSceneThumbnailPixmap(pix, proxy, pSceneIndex)
event->accept(); , bButtonsVisible(false)
updateButtonsState(); , bCanDelete(false)
update(); , bCanMoveUp(false)
} , bCanMoveDown(false)
{
void UBSceneThumbnailNavigPixmap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) setAcceptsHoverEvents(true);
{ setFlag(QGraphicsItem::ItemIsSelectable, true);
event->accept(); }
bButtonsVisible = false;
update(); UBSceneThumbnailNavigPixmap::~UBSceneThumbnailNavigPixmap()
} {
void UBSceneThumbnailNavigPixmap::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) }
{
Q_UNUSED(option); void UBSceneThumbnailNavigPixmap::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(widget); {
event->accept();
UBSceneThumbnailPixmap::paint(painter, option, widget); updateButtonsState();
if(bButtonsVisible) update();
{ }
if(bCanDelete)
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/close.svg")); void UBSceneThumbnailNavigPixmap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
else {
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/closeDisabled.svg")); event->accept();
if(bCanMoveUp) bButtonsVisible = false;
painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg")); update();
else }
painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg"));
if(bCanMoveDown) void UBSceneThumbnailNavigPixmap::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg")); {
else Q_UNUSED(option);
painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg")); Q_UNUSED(widget);
}
} UBSceneThumbnailPixmap::paint(painter, option, widget);
if(bButtonsVisible)
void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *event) {
{ if(bCanDelete)
QPointF p = event->pos(); painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/close.svg"));
else
// Here we check the position of the click and verify if it has to trig an action or not. painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/closeDisabled.svg"));
if(bCanDelete && p.x() >= 0 && p.x() <= BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE) if(bCanMoveUp)
{ painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg"));
deletePage(); else
} painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg"));
if(bCanMoveUp && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE) if(bCanMoveDown)
{ painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg"));
moveUpPage(); else
} painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg"));
if(bCanMoveDown && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 2*(BUTTONSIZE + BUTTONSPACING) + BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE) }
{ }
moveDownPage();
} void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept(); {
} QPointF p = event->pos();
void UBSceneThumbnailNavigPixmap::updateButtonsState() // Here we check the position of the click and verify if it has to trig an action or not.
{ if(bCanDelete && p.x() >= 0 && p.x() <= BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE)
bCanDelete = false; {
bCanMoveUp = false; deletePage();
bCanMoveDown = false; }
if(bCanMoveUp && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
UBDocumentProxy* p = proxy(); {
if(NULL != p) moveUpPage();
{ }
int iNbPages = p->pageCount(); if(bCanMoveDown && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 2*(BUTTONSIZE + BUTTONSPACING) + BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE)
if(1 < iNbPages) {
{ moveDownPage();
bCanDelete = true; }
if(sceneIndex() > 0) event->accept();
{ }
bCanMoveUp = true;
} void UBSceneThumbnailNavigPixmap::updateButtonsState()
if(sceneIndex() != iNbPages - 1) {
{ bCanDelete = false;
bCanMoveDown = true; bCanMoveUp = false;
} bCanMoveDown = false;
}
} UBDocumentProxy* p = proxy();
if(NULL != p)
if(bCanDelete || bCanMoveUp || bCanMoveDown) {
{ int iNbPages = p->pageCount();
bButtonsVisible = true; if(1 < iNbPages)
} {
} bCanDelete = true;
if(sceneIndex() > 0)
void UBSceneThumbnailNavigPixmap::deletePage() {
{ bCanMoveUp = true;
QList<QGraphicsItem*> itemsToDelete; }
itemsToDelete << this; if(sceneIndex() != iNbPages - 1)
{
UBApplication::documentController->deletePages(itemsToDelete); bCanMoveDown = true;
} }
}
void UBSceneThumbnailNavigPixmap::moveUpPage() }
{
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() - 1); if(bCanDelete || bCanMoveUp || bCanMoveDown)
} {
bButtonsVisible = true;
void UBSceneThumbnailNavigPixmap::moveDownPage() }
{ }
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() + 1);
} void UBSceneThumbnailNavigPixmap::deletePage()
{
void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal height) QList<QGraphicsItem*> itemsToDelete;
{ itemsToDelete << this;
int labelSpacing = 0;
if(this->caption) UBApplication::documentController->deletePages(itemsToDelete);
{ }
QFontMetrics fm(this->caption->font());
labelSpacing = UBSettings::thumbnailSpacing + fm.height(); void UBSceneThumbnailNavigPixmap::moveUpPage()
} {
if(this->thumbnail) UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() - 1);
{ }
int w = this->thumbnail->boundingRect().width();
int h = this->thumbnail->boundingRect().height(); void UBSceneThumbnailNavigPixmap::moveDownPage()
{
qreal scaleWidth = width / w; UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() + 1);
qreal scaleHeight = height / h; }
qreal scaleFactor = qMin(scaleWidth, scaleHeight);
UBThumbnail* pix = dynamic_cast<UBThumbnail*>(this->thumbnail); void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal height)
{
if(pix) int labelSpacing = 0;
{ if(this->caption)
scaleFactor = qMin(scaleFactor, 1.0); {
} QFontMetrics fm(this->caption->font());
labelSpacing = UBSettings::thumbnailSpacing + fm.height();
QTransform transform; }
transform.scale(scaleFactor, scaleFactor); if(this->thumbnail)
{
// Apply the scaling int w = this->thumbnail->boundingRect().width();
this->thumbnail->setTransform(transform); int h = this->thumbnail->boundingRect().height();
this->thumbnail->setFlag(QGraphicsItem::ItemIsSelectable, true);
qreal scaleWidth = width / w;
if(pix) qreal scaleHeight = height / h;
{ qreal scaleFactor = qMin(scaleWidth, scaleHeight);
pix->setColumn(col); UBThumbnail* pix = dynamic_cast<UBThumbnail*>(this->thumbnail);
pix->setRow(row);
} if(pix)
{
QPointF pos(border + (width - w * scaleFactor) / 2 + col * (width + border), scaleFactor = qMin(scaleFactor, 1.0);
border + row * (height + border + labelSpacing) + (height - h * scaleFactor) / 2); }
this->thumbnail->setPos(pos); QTransform transform;
transform.scale(scaleFactor, scaleFactor);
if(this->caption)
{ // Apply the scaling
QFontMetrics fm(this->caption->font()); this->thumbnail->setTransform(transform);
QString elidedText = fm.elidedText(this->caption->toPlainText(), Qt::ElideRight, width); this->thumbnail->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->caption->setPlainText(elidedText); if(pix)
this->caption->setWidth(fm.width(elidedText) + 2 * this->caption->document()->documentMargin()); {
pos.setY(pos.y() + (height + h * scaleFactor) / 2 + 5); // What is this 5 ?? pix->setColumn(col);
qreal labelWidth = fm.width(elidedText); pix->setRow(row);
pos.setX(border + (width - labelWidth) / 2 + col * (width + border)); }
this->caption->setPos(pos);
} QPointF pos(border + (width - w * scaleFactor) / 2 + col * (width + border),
} border + row * (height + border + labelSpacing) + (height - h * scaleFactor) / 2);
}
this->thumbnail->setPos(pos);
if(this->caption)
{
QFontMetrics fm(this->caption->font());
QString elidedText = fm.elidedText(this->caption->toPlainText(), Qt::ElideRight, width);
this->caption->setPlainText(elidedText);
this->caption->setWidth(fm.width(elidedText) + 2 * this->caption->document()->documentMargin());
pos.setY(pos.y() + (height + h * scaleFactor) / 2 + 5); // What is this 5 ??
qreal labelWidth = fm.width(elidedText);
pos.setX(border + (width - labelWidth) / 2 + col * (width + border));
this->caption->setPos(pos);
}
}
}
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBTHUMBNAILWIDGET_H_ #ifndef UBTHUMBNAILWIDGET_H_
#define UBTHUMBNAILWIDGET_H_ #define UBTHUMBNAILWIDGET_H_
#include <QtGui> #include <QtGui>
#include <QtSvg> #include <QtSvg>
#include <QTime> #include <QTime>
#include <QGraphicsSceneHoverEvent> #include <QGraphicsSceneHoverEvent>
#include "frameworks/UBCoreGraphicsScene.h" #include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#define STARTDRAGTIME 1000000 #define STARTDRAGTIME 1000000
#define BUTTONSIZE 48 #define BUTTONSIZE 48
#define BUTTONSPACING 5 #define BUTTONSPACING 5
class UBDocumentProxy; class UBDocumentProxy;
class UBThumbnailTextItem; class UBThumbnailTextItem;
class UBThumbnail; class UBThumbnail;
class UBThumbnailWidget : public QGraphicsView class UBThumbnailWidget : public QGraphicsView
{ {
Q_OBJECT; Q_OBJECT;
public: public:
UBThumbnailWidget(QWidget* parent); UBThumbnailWidget(QWidget* parent);
virtual ~UBThumbnailWidget(); virtual ~UBThumbnailWidget();
QList<QGraphicsItem*> selectedItems(); QList<QGraphicsItem*> selectedItems();
void selectItemAt(int pIndex, bool extend = false); void selectItemAt(int pIndex, bool extend = false);
void unselectItemAt(int pIndex); void unselectItemAt(int pIndex);
qreal thumbnailWidth() qreal thumbnailWidth()
{ {
return mThumbnailWidth; return mThumbnailWidth;
} }
void setBackgroundBrush(const QBrush& brush) void setBackgroundBrush(const QBrush& brush)
{ {
mThumbnailsScene.setBackgroundBrush(brush); mThumbnailsScene.setBackgroundBrush(brush);
} }
public slots: public slots:
void setThumbnailWidth(qreal pThumbnailWidth); void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing); void setSpacing(qreal pSpacing);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString("")); virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
void refreshScene(); void refreshScene();
void sceneSelectionChanged(); void sceneSelectionChanged();
signals: signals:
void resized(); void resized();
void selectionChanged(); void selectionChanged();
void mouseDoubleClick(QGraphicsItem* item, int index); void mouseDoubleClick(QGraphicsItem* item, int index);
void mouseClick(QGraphicsItem* item, int index); void mouseClick(QGraphicsItem* item, int index);
protected: protected:
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent * event); virtual void resizeEvent(QResizeEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event); void mouseDoubleClickEvent(QMouseEvent * event);
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
virtual void focusInEvent(QFocusEvent *event); virtual void focusInEvent(QFocusEvent *event);
QList<QGraphicsItem*> mGraphicItems; QList<QGraphicsItem*> mGraphicItems;
QList<UBThumbnailTextItem*> mLabelsItems; QList<UBThumbnailTextItem*> mLabelsItems;
QPointF mMousePressScenePos; QPointF mMousePressScenePos;
QPoint mMousePressPos; QPoint mMousePressPos;
protected: protected:
qreal spacing() { return mSpacing; } qreal spacing() { return mSpacing; }
QList<QUrl> mItemsPaths; QList<QUrl> mItemsPaths;
QStringList mLabels; QStringList mLabels;
bool bSelectionInProgress; bool bSelectionInProgress;
bool bCanDrag; bool bCanDrag;
private: private:
void selectAll(); void selectAll();
void unselectAll(); void selectItems(int startIndex, int count);
void selectItems(int startIndex, int count); int rowCount() const;
int rowCount() const; int columnCount() const;
int columnCount() const;
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
void deleteLasso();
void deleteLasso();
UBCoreGraphicsScene mThumbnailsScene;
UBCoreGraphicsScene mThumbnailsScene;
QString mMimeType;
QString mMimeType;
QPointF prevMoveMousePos;
qreal mThumbnailWidth;
qreal mThumbnailHeight; qreal mThumbnailWidth;
qreal mSpacing; qreal mThumbnailHeight;
qreal mSpacing;
UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan; UBThumbnail *mLastSelectedThumbnail;
QGraphicsRectItem *mLassoRectItem; int mSelectionSpan;
QList<QGraphicsItem*> mSelectedThumbnailItems; QGraphicsRectItem *mLassoRectItem;
QTime mClickTime; QSet<QGraphicsItem*> mSelectedThumbnailItems;
}; QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItems;
QTime mClickTime;
};
class UBThumbnail
{
public: class UBThumbnail
UBThumbnail(); {
public:
virtual ~UBThumbnail(); UBThumbnail();
QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option) virtual ~UBThumbnail();
{
// Never draw the rubber band, we draw our custom selection with the DelegateFrame QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option)
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); {
styleOption.state &= ~QStyle::State_Selected; // Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
return styleOption; styleOption.state &= ~QStyle::State_Selected;
}
return styleOption;
virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value) }
{
Q_UNUSED(value); virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if ((change == QGraphicsItem::ItemSelectedHasChanged Q_UNUSED(value);
|| change == QGraphicsItem::ItemTransformHasChanged
|| change == QGraphicsItem::ItemPositionHasChanged) if ((change == QGraphicsItem::ItemSelectedHasChanged
&& item->scene()) || change == QGraphicsItem::ItemTransformHasChanged
{ || change == QGraphicsItem::ItemPositionHasChanged)
if (item->isSelected()) && item->scene())
{ {
if (!mSelectionItem->scene()) if (item->isSelected())
{ {
item->scene()->addItem(mSelectionItem); if (!mSelectionItem->scene())
mSelectionItem->setZValue(item->zValue() - 1); {
// UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1); item->scene()->addItem(mSelectionItem);
mAddedToScene = true; mSelectionItem->setZValue(item->zValue() - 1);
} // UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1);
mAddedToScene = true;
mSelectionItem->setRect( }
item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().y() - 5, mSelectionItem->setRect(
item->sceneBoundingRect().width() + 10, item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().height() + 10); item->sceneBoundingRect().y() - 5,
item->sceneBoundingRect().width() + 10,
mSelectionItem->show(); item->sceneBoundingRect().height() + 10);
} mSelectionItem->show();
else
{ }
mSelectionItem->hide(); else
} {
} mSelectionItem->hide();
} }
}
int column() { return mColumn; } }
void setColumn(int column) { mColumn = column; }
int row() { return mRow; } int column() { return mColumn; }
void setRow(int row) { mRow = row; } void setColumn(int column) { mColumn = column; }
int row() { return mRow; }
protected: void setRow(int row) { mRow = row; }
QGraphicsRectItem *mSelectionItem;
private: protected:
bool mAddedToScene; QGraphicsRectItem *mSelectionItem;
private:
int mColumn; bool mAddedToScene;
int mRow;
}; int mColumn;
int mRow;
};
class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
{
public: class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
UBThumbnailSvg(const QString& path) {
: QGraphicsSvgItem(path) public:
{ UBThumbnailSvg(const QString& path)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); : QGraphicsSvgItem(path)
} {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
virtual ~UBThumbnailSvg() }
{
// NOOP virtual ~UBThumbnailSvg()
} {
// NOOP
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) }
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsSvgItem::paint(painter, &styleOption, widget); {
} QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsSvgItem::paint(painter, &styleOption, widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) }
{
UBThumbnail::itemChange(this, change, value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsSvgItem::itemChange(change, value); {
} UBThumbnail::itemChange(this, change, value);
return QGraphicsSvgItem::itemChange(change, value);
}; }
};
class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
{
public: class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
UBThumbnailPixmap(const QPixmap& pix) {
: QGraphicsPixmapItem(pix) public:
{ UBThumbnailPixmap(const QPixmap& pix)
setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable : QGraphicsPixmapItem(pix)
setShapeMode(QGraphicsPixmapItem::BoundingRectShape); {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable
} setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
virtual ~UBThumbnailPixmap() }
{
// NOOP virtual ~UBThumbnailPixmap()
} {
// NOOP
virtual QPainterPath shape () const }
{
QPainterPath path; virtual QPainterPath shape () const
path.addRect(boundingRect()); {
return path; QPainterPath path;
} path.addRect(boundingRect());
return path;
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsPixmapItem::paint(painter, &styleOption, widget); {
} QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsPixmapItem::paint(painter, &styleOption, widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) }
{
UBThumbnail::itemChange(this, change, value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsPixmapItem::itemChange(change, value); {
} UBThumbnail::itemChange(this, change, value);
}; return QGraphicsPixmapItem::itemChange(change, value);
}
};
class UBSceneThumbnailPixmap : public UBThumbnailPixmap
{
public: class UBSceneThumbnailPixmap : public UBThumbnailPixmap
UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex) {
: UBThumbnailPixmap(pix) public:
, mProxy(proxy) UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
, mSceneIndex(pSceneIndex) : UBThumbnailPixmap(pix)
{ , mProxy(proxy)
// NOOP , mSceneIndex(pSceneIndex)
} {
// NOOP
virtual ~UBSceneThumbnailPixmap() }
{
// NOOP virtual ~UBSceneThumbnailPixmap()
} {
// NOOP
UBDocumentProxy* proxy() }
{
return mProxy; UBDocumentProxy* proxy()
} {
return mProxy;
int sceneIndex() }
{
return mSceneIndex; int sceneIndex()
} {
return mSceneIndex;
void highlight() }
{
//NOOP void highlight()
} {
//NOOP
private: }
UBDocumentProxy* mProxy;
int mSceneIndex; private:
}; UBDocumentProxy* mProxy;
int mSceneIndex;
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap };
{
public: class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex); {
~UBSceneThumbnailNavigPixmap(); public:
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
protected: ~UBSceneThumbnailNavigPixmap();
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private: void mousePressEvent(QGraphicsSceneMouseEvent *event);
void updateButtonsState();
void deletePage(); private:
void moveUpPage(); void updateButtonsState();
void moveDownPage(); void deletePage();
void moveUpPage();
bool bButtonsVisible; void moveDownPage();
bool bCanDelete;
bool bCanMoveUp; bool bButtonsVisible;
bool bCanMoveDown; bool bCanDelete;
}; bool bCanMoveUp;
bool bCanMoveDown;
class UBThumbnailVideo : public UBThumbnailPixmap };
{
public: class UBThumbnailVideo : public UBThumbnailPixmap
UBThumbnailVideo(const QUrl &path) {
: UBThumbnailPixmap(QPixmap(":/images/movie.svg")) public:
, mPath(path) UBThumbnailVideo(const QUrl &path)
{ : UBThumbnailPixmap(QPixmap(":/images/movie.svg"))
// NOOP , mPath(path)
} {
// NOOP
virtual ~UBThumbnailVideo() }
{
// NOOP virtual ~UBThumbnailVideo()
} {
// NOOP
QUrl path() }
{
return mPath; QUrl path()
} {
return mPath;
private: }
QUrl mPath; private:
};
QUrl mPath;
class UBThumbnailTextItem : public QGraphicsTextItem };
{
public: class UBThumbnailTextItem : public QGraphicsTextItem
UBThumbnailTextItem(const QString& text) {
: QGraphicsTextItem(text) public:
, mUnelidedText(text) UBThumbnailTextItem(const QString& text)
, mIsHighlighted(false) : QGraphicsTextItem(text)
{ , mUnelidedText(text)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); , mIsHighlighted(false)
} {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));} }
void setWidth(qreal pWidth) QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}
{
if (mWidth != pWidth) void setWidth(qreal pWidth)
{ {
prepareGeometryChange(); if (mWidth != pWidth)
mWidth = pWidth; {
computeText(); prepareGeometryChange();
} mWidth = pWidth;
}; computeText();
}
qreal width() {return mWidth;} };
void highlight() qreal width() {return mWidth;}
{
if (!mIsHighlighted) void highlight()
{ {
mIsHighlighted = true; if (!mIsHighlighted)
computeText(); {
} mIsHighlighted = true;
} computeText();
}
void computeText() }
{
QFontMetricsF fm(font()); void computeText()
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth); {
QFontMetricsF fm(font());
if (mIsHighlighted) QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth);
{
setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>"); if (mIsHighlighted)
} {
else setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>");
{ }
setPlainText(elidedText); else
} {
} setPlainText(elidedText);
}
private: }
qreal mWidth;
QString mUnelidedText; private:
bool mIsHighlighted; qreal mWidth;
}; QString mUnelidedText;
bool mIsHighlighted;
class UBImgTextThumbnailElement };
{
private: class UBImgTextThumbnailElement
QGraphicsItem* thumbnail; {
UBThumbnailTextItem* caption; private:
int border; QGraphicsItem* thumbnail;
UBThumbnailTextItem* caption;
public: int border;
UBImgTextThumbnailElement(QGraphicsItem* thumb, UBThumbnailTextItem* text): border(0)
{ public:
this->thumbnail = thumb; UBImgTextThumbnailElement(QGraphicsItem* thumb, UBThumbnailTextItem* text): border(0)
this->caption = text; {
} this->thumbnail = thumb;
this->caption = text;
QGraphicsItem* getThumbnail() const { return this->thumbnail; } }
void setThumbnail(QGraphicsItem* newGItem) { this->thumbnail = newGItem; }
QGraphicsItem* getThumbnail() const { return this->thumbnail; }
UBThumbnailTextItem* getCaption() const { return this->caption; } void setThumbnail(QGraphicsItem* newGItem) { this->thumbnail = newGItem; }
void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
UBThumbnailTextItem* getCaption() const { return this->caption; }
void Place(int row, int col, qreal width, qreal height); void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
int getBorder() const { return this->border; } void Place(int row, int col, qreal width, qreal height);
void setBorder(int newBorder) { this->border = newBorder; }
}; int getBorder() const { return this->border; }
void setBorder(int newBorder) { this->border = newBorder; }
};
#endif /* UBTHUMBNAILWIDGET_H_ */
#endif /* UBTHUMBNAILWIDGET_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment