Changeset View
Changeset View
Standalone View
Standalone View
src/views/collectionview/calendardelegate.cpp
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Line(s) | |||||
219 | bool StyledCalendarDelegate::editorEvent(QEvent *event, | 219 | bool StyledCalendarDelegate::editorEvent(QEvent *event, | ||
220 | QAbstractItemModel *model, | 220 | QAbstractItemModel *model, | ||
221 | const QStyleOptionViewItem &option, | 221 | const QStyleOptionViewItem &option, | ||
222 | const QModelIndex &index) | 222 | const QModelIndex &index) | ||
223 | { | 223 | { | ||
224 | Q_ASSERT(event); | 224 | Q_ASSERT(event); | ||
225 | Q_ASSERT(model); | 225 | Q_ASSERT(model); | ||
226 | 226 | | |||
227 | // double-click mouse starts the quickview dialog | ||||
228 | if (event->type() == QEvent::MouseButtonDblClick) { | ||||
229 | Q_EMIT action(index, Quickview); | ||||
230 | return true; | ||||
231 | } | ||||
232 | | ||||
227 | int button = -1; | 233 | int button = -1; | ||
228 | // make sure that we have the right event type | 234 | // make sure that we have the right event type | ||
229 | if ((event->type() == QEvent::MouseButtonRelease) | 235 | if ((event->type() == QEvent::MouseButtonRelease) || | ||
230 | || (event->type() == QEvent::MouseButtonDblClick) | 236 | (event->type() == QEvent::MouseButtonPress)) { | ||
231 | || (event->type() == QEvent::MouseButtonPress)) { | | |||
232 | 237 | | |||
233 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | 238 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | ||
234 | 239 | | |||
235 | for (int i = 1; i < 4; i++) { | 240 | for (int i = 1; i < 4; i++) { | ||
236 | if (enableButtonRect(option.rect, i).contains(me->pos())) { | 241 | if (enableButtonRect(option.rect, i).contains(me->pos())) { | ||
237 | button = i; | 242 | button = i; | ||
238 | break; | 243 | break; | ||
239 | } | 244 | } | ||
240 | } | 245 | } | ||
246 | | ||||
241 | if (me->button() != Qt::LeftButton || button < 0) { | 247 | if (me->button() != Qt::LeftButton || button < 0) { | ||
242 | return QStyledItemDelegate::editorEvent(event, model, option, index); | 248 | return QStyledItemDelegate::editorEvent(event, model, option, index); | ||
243 | } | 249 | } | ||
244 | 250 | | |||
245 | if ((event->type() == QEvent::MouseButtonPress) | 251 | if (event->type() == QEvent::MouseButtonPress) { | ||
246 | || (event->type() == QEvent::MouseButtonDblClick)) { | | |||
247 | return true; | 252 | return true; | ||
248 | } | 253 | } | ||
254 | | ||||
249 | } else { | 255 | } else { | ||
250 | return QStyledItemDelegate::editorEvent(event, model, option, index); | 256 | return QStyledItemDelegate::editorEvent(event, model, option, index); | ||
251 | } | 257 | } | ||
252 | 258 | | |||
253 | Q_ASSERT(button > 0); | 259 | Q_ASSERT(button > 0); | ||
254 | QStyleOptionViewItem opt = option; | 260 | QStyleOptionViewItem opt = option; | ||
255 | opt.state |= QStyle::State_MouseOver; | 261 | opt.state |= QStyle::State_MouseOver; | ||
256 | 262 | | |||
257 | QList<StyledCalendarDelegate::Action> actions = getActions(opt, index); | 263 | QList<StyledCalendarDelegate::Action> actions = getActions(opt, index); | ||
258 | if (actions.count() >= button) { | 264 | if (actions.count() >= button) { | ||
259 | const Action a = actions.at(button - 1); | 265 | const Action a = actions.at(button - 1); | ||
260 | Q_EMIT action(index, a); | 266 | Q_EMIT action(index, a); | ||
261 | return true; | 267 | return true; | ||
262 | } | 268 | } | ||
263 | return QStyledItemDelegate::editorEvent(event, model, option, index); | 269 | return QStyledItemDelegate::editorEvent(event, model, option, index); | ||
264 | } | 270 | } | ||
265 | 271 | | |||
266 | QSize StyledCalendarDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const | 272 | QSize StyledCalendarDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
267 | { | 273 | { | ||
268 | QSize size = QStyledItemDelegate::sizeHint(option, index); | 274 | QSize size = QStyledItemDelegate::sizeHint(option, index); | ||
269 | //Without this adjustment toplevel resource folders get a slightly greater height, which looks silly and breaks the toolbutton position. | 275 | //Without this adjustment toplevel resource folders get a slightly greater height, which looks silly and breaks the toolbutton position. | ||
270 | size.setHeight(mPixmap.value(AddToList).height() + 4); | 276 | size.setHeight(mPixmap.value(AddToList).height() + 4); | ||
271 | return size; | 277 | return size; | ||
272 | } | 278 | } | ||
273 | |