2010-03-29 18:59:01 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-29 18:59:01 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "playlistdelegates.h"
|
2010-07-11 18:17:38 +02:00
|
|
|
#include "queue.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/utilities.h"
|
|
|
|
#include "library/librarybackend.h"
|
|
|
|
#include "widgets/trackslider.h"
|
2010-10-17 19:10:19 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-03-29 18:59:01 +02:00
|
|
|
|
|
|
|
#include <QDateTime>
|
2010-08-28 21:07:23 +02:00
|
|
|
#include <QDir>
|
2010-12-25 14:11:09 +01:00
|
|
|
#include <QFuture>
|
|
|
|
#include <QFutureWatcher>
|
2010-12-04 17:43:09 +01:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QHelpEvent>
|
|
|
|
#include <QLinearGradient>
|
2010-03-29 18:59:01 +02:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPainter>
|
2010-12-04 17:43:09 +01:00
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QTextDocument>
|
2010-04-30 17:23:52 +02:00
|
|
|
#include <QToolTip>
|
|
|
|
#include <QWhatsThis>
|
2010-12-25 14:11:09 +01:00
|
|
|
#include <QtConcurrentRun>
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2010-07-11 20:37:42 +02:00
|
|
|
const int QueuedItemDelegate::kQueueBoxBorder = 1;
|
|
|
|
const int QueuedItemDelegate::kQueueBoxCornerRadius = 3;
|
|
|
|
const int QueuedItemDelegate::kQueueBoxLength = 30;
|
|
|
|
const QRgb QueuedItemDelegate::kQueueBoxGradientColor1 = qRgb(102, 150, 227);
|
|
|
|
const QRgb QueuedItemDelegate::kQueueBoxGradientColor2 = qRgb(77, 121, 200);
|
|
|
|
const int QueuedItemDelegate::kQueueOpacitySteps = 10;
|
|
|
|
const float QueuedItemDelegate::kQueueOpacityLowerBound = 0.4;
|
|
|
|
|
2010-10-17 19:10:19 +02:00
|
|
|
const int PlaylistDelegateBase::kMinHeight = 19;
|
|
|
|
|
2010-07-11 23:27:36 +02:00
|
|
|
QueuedItemDelegate::QueuedItemDelegate(QObject *parent, int indicator_column)
|
|
|
|
: QStyledItemDelegate(parent),
|
|
|
|
indicator_column_(indicator_column)
|
2010-07-11 18:17:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueuedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
|
2010-07-11 23:27:36 +02:00
|
|
|
if (index.column() == indicator_column_) {
|
2010-08-28 21:07:23 +02:00
|
|
|
bool ok = false;
|
|
|
|
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt(&ok);
|
|
|
|
if (ok && queue_pos != -1) {
|
2010-07-11 18:17:38 +02:00
|
|
|
float opacity = kQueueOpacitySteps - qMin(kQueueOpacitySteps, queue_pos);
|
|
|
|
opacity /= kQueueOpacitySteps;
|
|
|
|
opacity *= 1.0 - kQueueOpacityLowerBound;
|
|
|
|
opacity += kQueueOpacityLowerBound;
|
|
|
|
painter->setOpacity(opacity);
|
|
|
|
|
2010-07-11 20:37:42 +02:00
|
|
|
DrawBox(painter, option.rect, option.font, QString::number(queue_pos+1),
|
|
|
|
kQueueBoxLength);
|
2010-07-11 18:17:38 +02:00
|
|
|
|
|
|
|
painter->setOpacity(1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-11 20:37:42 +02:00
|
|
|
void QueuedItemDelegate::DrawBox(
|
|
|
|
QPainter* painter, const QRect& line_rect, const QFont& font,
|
|
|
|
const QString& text, int width) const {
|
|
|
|
QFont smaller = font;
|
2010-08-28 21:07:23 +02:00
|
|
|
smaller.setPointSize(smaller.pointSize() - 1);
|
2010-07-11 20:37:42 +02:00
|
|
|
smaller.setBold(true);
|
|
|
|
|
|
|
|
if (width == -1)
|
|
|
|
width = QFontMetrics(font).width(text + " ");
|
|
|
|
|
|
|
|
QRect rect(line_rect);
|
|
|
|
rect.setLeft(rect.right() - width - kQueueBoxBorder);
|
|
|
|
rect.setWidth(width);
|
|
|
|
rect.setTop(rect.top() + kQueueBoxBorder);
|
|
|
|
rect.setBottom(rect.bottom() - kQueueBoxBorder - 1);
|
|
|
|
|
|
|
|
QRect text_rect(rect);
|
|
|
|
text_rect.setBottom(text_rect.bottom() + 1);
|
|
|
|
|
|
|
|
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
|
|
|
|
gradient.setColorAt(0.0, kQueueBoxGradientColor1);
|
|
|
|
gradient.setColorAt(1.0, kQueueBoxGradientColor2);
|
|
|
|
|
|
|
|
// Turn on antialiasing
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
// Draw the box
|
|
|
|
painter->setPen(QPen(Qt::white, 1));
|
|
|
|
painter->setBrush(gradient);
|
|
|
|
painter->drawRoundedRect(rect, kQueueBoxCornerRadius, kQueueBoxCornerRadius);
|
|
|
|
|
|
|
|
// Draw the text
|
|
|
|
painter->setFont(smaller);
|
|
|
|
painter->drawText(rect, Qt::AlignCenter, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
int QueuedItemDelegate::queue_indicator_size(const QModelIndex& index) const {
|
2010-07-11 23:27:36 +02:00
|
|
|
if (index.column() == indicator_column_) {
|
2010-07-11 20:37:42 +02:00
|
|
|
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt();
|
|
|
|
if (queue_pos != -1) {
|
|
|
|
return kQueueBoxLength + kQueueBoxBorder*2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-28 21:07:23 +02:00
|
|
|
PlaylistDelegateBase::PlaylistDelegateBase(QObject* parent, const QString& suffix)
|
|
|
|
: QueuedItemDelegate(parent),
|
|
|
|
view_(qobject_cast<QTreeView*>(parent)),
|
2010-06-10 19:04:40 +02:00
|
|
|
suffix_(suffix)
|
2010-03-29 18:59:01 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PlaylistDelegateBase::displayText(const QVariant& value, const QLocale&) const {
|
2010-06-10 19:04:40 +02:00
|
|
|
QString text;
|
|
|
|
|
2010-11-03 22:19:26 +01:00
|
|
|
switch (static_cast<QMetaType::Type>(value.type())) {
|
|
|
|
case QMetaType::Int: {
|
2010-03-29 18:59:01 +02:00
|
|
|
int v = value.toInt();
|
2010-06-10 19:04:40 +02:00
|
|
|
if (v > 0)
|
|
|
|
text = QString::number(v);
|
|
|
|
break;
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:54:07 +02:00
|
|
|
case QMetaType::Float:
|
2010-11-03 22:19:26 +01:00
|
|
|
case QMetaType::Double: {
|
2010-03-29 18:59:01 +02:00
|
|
|
double v = value.toDouble();
|
2010-06-10 19:04:40 +02:00
|
|
|
if (v > 0)
|
|
|
|
text = QString::number(v);
|
|
|
|
break;
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2010-06-10 19:04:40 +02:00
|
|
|
text = value.toString();
|
|
|
|
break;
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
2010-06-10 19:04:40 +02:00
|
|
|
|
|
|
|
if (!text.isNull() && !suffix_.isNull())
|
|
|
|
text += " " + suffix_;
|
|
|
|
return text;
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
2010-04-12 20:07:07 +02:00
|
|
|
QSize PlaylistDelegateBase::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
2010-07-11 18:17:38 +02:00
|
|
|
QSize size = QueuedItemDelegate::sizeHint(option, index);
|
2010-04-12 20:07:07 +02:00
|
|
|
if (size.height() < kMinHeight)
|
|
|
|
size.setHeight(kMinHeight);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2010-03-29 18:59:01 +02:00
|
|
|
void PlaylistDelegateBase::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
2010-07-11 18:17:38 +02:00
|
|
|
QueuedItemDelegate::paint(painter, Adjusted(option, index), index);
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2010-07-11 18:17:38 +02:00
|
|
|
// Stop after indicator
|
2010-07-11 20:37:42 +02:00
|
|
|
if (index.column() == Playlist::Column_Title) {
|
2010-03-29 18:59:01 +02:00
|
|
|
if (index.data(Playlist::Role_StopAfter).toBool()) {
|
2010-07-11 20:37:42 +02:00
|
|
|
QRect rect(option.rect);
|
|
|
|
rect.setRight(rect.right() - queue_indicator_size(index));
|
|
|
|
|
|
|
|
DrawBox(painter, rect, option.font, tr("stop"));
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
2010-08-28 21:07:23 +02:00
|
|
|
if (!view_)
|
|
|
|
return option;
|
|
|
|
|
2010-06-09 17:37:54 +02:00
|
|
|
QPoint top_left(-view_->horizontalScrollBar()->value(),
|
|
|
|
-view_->verticalScrollBar()->value());
|
|
|
|
|
|
|
|
if (view_->header()->logicalIndexAt(top_left) != index.column())
|
2010-03-29 18:59:01 +02:00
|
|
|
return option;
|
|
|
|
|
|
|
|
QStyleOptionViewItemV4 ret(option);
|
|
|
|
|
|
|
|
if (index.data(Playlist::Role_IsCurrent).toBool()) {
|
|
|
|
// Move the text in a bit on the first column for the song that's currently
|
|
|
|
// playing
|
|
|
|
ret.rect.setLeft(ret.rect.left() + 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-30 17:23:52 +02:00
|
|
|
bool PlaylistDelegateBase::helpEvent(QHelpEvent *event, QAbstractItemView *view,
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) {
|
|
|
|
// This function is copied from QAbstractItemDelegate, and changed to show
|
|
|
|
// displayText() in the tooltip, rather than the index's naked
|
|
|
|
// Qt::ToolTipRole text.
|
|
|
|
|
|
|
|
Q_UNUSED(option);
|
|
|
|
|
|
|
|
if (!event || !view)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QHelpEvent *he = static_cast<QHelpEvent*>(event);
|
|
|
|
QString text = displayText(index.data(), QLocale::system());
|
|
|
|
|
2010-12-04 17:43:09 +01:00
|
|
|
// Special case: we want newlines in the comment tooltip
|
|
|
|
if (index.column() == Playlist::Column_Comment) {
|
|
|
|
text = Qt::escape(index.data(Qt::ToolTipRole).toString());
|
2010-12-05 14:41:40 +01:00
|
|
|
text.replace("\\r\\n", "<br />");
|
|
|
|
text.replace("\\n", "<br />");
|
|
|
|
text.replace("\r\n", "<br />");
|
2010-12-04 17:43:09 +01:00
|
|
|
text.replace("\n", "<br />");
|
|
|
|
}
|
|
|
|
|
2010-04-30 17:23:52 +02:00
|
|
|
if (text.isEmpty() || !he)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (event->type()) {
|
2011-02-03 00:27:55 +01:00
|
|
|
case QEvent::ToolTip: {
|
|
|
|
QRect displayed_text;
|
|
|
|
QSize real_text;
|
|
|
|
bool is_elided = false;
|
|
|
|
|
2011-02-02 23:58:19 +01:00
|
|
|
real_text = sizeHint(option, index);
|
|
|
|
displayed_text = view->visualRect(index);
|
|
|
|
is_elided = displayed_text.width() < real_text.width();
|
|
|
|
if(is_elided) {
|
|
|
|
QToolTip::showText(he->globalPos(), text, view);
|
|
|
|
} else { // in case that another text was previously displayed
|
|
|
|
QToolTip::hideText();
|
|
|
|
}
|
2010-04-30 17:23:52 +02:00
|
|
|
return true;
|
2011-02-03 00:27:55 +01:00
|
|
|
}
|
2010-04-30 17:23:52 +02:00
|
|
|
|
|
|
|
case QEvent::QueryWhatsThis:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case QEvent::WhatsThis:
|
|
|
|
QWhatsThis::showText(he->globalPos(), text, view);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-29 18:59:01 +02:00
|
|
|
|
|
|
|
QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) const {
|
|
|
|
bool ok = false;
|
2011-02-13 19:34:30 +01:00
|
|
|
qint64 nanoseconds = value.toLongLong(&ok);
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2011-02-13 19:34:30 +01:00
|
|
|
if (ok && nanoseconds > 0)
|
|
|
|
return Utilities::PrettyTimeNanosec(nanoseconds);
|
2010-03-29 18:59:01 +02:00
|
|
|
return QString::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString SizeItemDelegate::displayText(const QVariant& value, const QLocale&) const {
|
|
|
|
bool ok = false;
|
|
|
|
int bytes = value.toInt(&ok);
|
2010-07-03 23:05:55 +02:00
|
|
|
|
|
|
|
if (ok)
|
|
|
|
return Utilities::PrettySize(bytes);
|
|
|
|
return QString();
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DateItemDelegate::displayText(const QVariant &value, const QLocale &locale) const {
|
|
|
|
bool ok = false;
|
|
|
|
int time = value.toInt(&ok);
|
|
|
|
|
|
|
|
if (!ok || time == -1)
|
|
|
|
return QString::null;
|
|
|
|
|
|
|
|
return QDateTime::fromTime_t(time).toString(
|
|
|
|
QLocale::system().dateTimeFormat(QLocale::ShortFormat));
|
|
|
|
}
|
|
|
|
|
2010-10-17 22:53:15 +02:00
|
|
|
QString LastPlayedItemDelegate::displayText(const QVariant& value, const QLocale& locale) const {
|
|
|
|
bool ok = false;
|
|
|
|
const int time = value.toInt(&ok);
|
|
|
|
|
|
|
|
if (!ok || time == -1)
|
|
|
|
return tr("Never");
|
|
|
|
|
|
|
|
return Utilities::Ago(time, locale);
|
|
|
|
}
|
|
|
|
|
2010-03-29 18:59:01 +02:00
|
|
|
QString FileTypeItemDelegate::displayText(const QVariant &value, const QLocale &locale) const {
|
|
|
|
bool ok = false;
|
|
|
|
Song::FileType type = Song::FileType(value.toInt(&ok));
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return tr("Unknown");
|
|
|
|
|
2010-07-31 16:14:03 +02:00
|
|
|
return Song::TextForFiletype(type);
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* TextItemDelegate::createEditor(
|
|
|
|
QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
|
|
|
return new QLineEdit(parent);
|
|
|
|
}
|
|
|
|
|
2010-10-17 19:10:19 +02:00
|
|
|
RatingItemDelegate::RatingItemDelegate(QObject* parent)
|
2010-10-23 18:56:54 +02:00
|
|
|
: PlaylistDelegateBase(parent)
|
2010-10-17 19:10:19 +02:00
|
|
|
{
|
2010-10-17 23:56:19 +02:00
|
|
|
}
|
2010-10-17 19:10:19 +02:00
|
|
|
|
2010-10-17 23:56:19 +02:00
|
|
|
void RatingItemDelegate::paint(
|
|
|
|
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
2010-10-17 20:21:30 +02:00
|
|
|
// Draw the background
|
|
|
|
const QStyleOptionViewItemV3* vopt =
|
|
|
|
qstyleoption_cast<const QStyleOptionViewItemV3*>(&option);
|
|
|
|
vopt->widget->style()->drawPrimitive(
|
|
|
|
QStyle::PE_PanelItemViewItem, vopt, painter, vopt->widget);
|
|
|
|
|
2010-10-17 23:56:19 +02:00
|
|
|
// Don't draw anything else if the user can't set the rating of this item
|
|
|
|
if (!index.data(Playlist::Role_CanSetRating).toBool())
|
|
|
|
return;
|
|
|
|
|
2010-12-11 15:53:43 +01:00
|
|
|
const bool hover = mouse_over_index_.isValid() && (
|
|
|
|
mouse_over_index_ == index || (
|
|
|
|
selected_indexes_.contains(mouse_over_index_) &&
|
|
|
|
selected_indexes_.contains(index)));
|
|
|
|
|
2010-10-26 21:59:55 +02:00
|
|
|
const double rating =
|
|
|
|
(hover ? RatingPainter::RatingForPos(mouse_over_pos_, option.rect)
|
|
|
|
: index.data().toDouble());
|
2010-10-17 23:56:19 +02:00
|
|
|
|
2010-10-26 21:59:55 +02:00
|
|
|
painter_.Paint(painter, option.rect, rating);
|
2010-10-17 19:10:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize RatingItemDelegate::sizeHint(
|
|
|
|
const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
|
|
|
QSize size = PlaylistDelegateBase::sizeHint(option, index);
|
2010-10-26 21:59:55 +02:00
|
|
|
size.setWidth(size.height() * RatingPainter::kStarCount);
|
2010-10-17 19:10:19 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RatingItemDelegate::displayText(
|
|
|
|
const QVariant& value, const QLocale&) const {
|
2010-10-17 22:53:15 +02:00
|
|
|
if (value.isNull() || value.toDouble() <= 0)
|
|
|
|
return QString();
|
|
|
|
|
2010-10-17 23:56:19 +02:00
|
|
|
// Round to the nearest 0.5
|
2010-10-26 21:59:55 +02:00
|
|
|
const double rating = float(int(value.toDouble() * RatingPainter::kStarCount * 2 + 0.5)) / 2;
|
2010-10-17 23:56:19 +02:00
|
|
|
|
2010-10-17 19:10:19 +02:00
|
|
|
return QString::number(rating, 'f', 1);
|
|
|
|
}
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2010-12-25 14:11:09 +01:00
|
|
|
TagCompletionModel::TagCompletionModel(LibraryBackend* backend, Playlist::Column column)
|
|
|
|
: QStringListModel()
|
|
|
|
{
|
|
|
|
QString col = database_column(column);
|
|
|
|
if (!col.isEmpty()) {
|
|
|
|
setStringList(backend->GetAll(col));
|
|
|
|
}
|
|
|
|
}
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2010-12-25 14:11:09 +01:00
|
|
|
QString TagCompletionModel::database_column(Playlist::Column column) {
|
|
|
|
switch (column) {
|
|
|
|
case Playlist::Column_Artist: return "artist";
|
|
|
|
case Playlist::Column_Album: return "album";
|
|
|
|
case Playlist::Column_AlbumArtist: return "albumartist";
|
|
|
|
case Playlist::Column_Composer: return "composer";
|
|
|
|
case Playlist::Column_Genre: return "genre";
|
2010-03-29 18:59:01 +02:00
|
|
|
default:
|
2010-12-25 14:11:09 +01:00
|
|
|
qWarning() << __PRETTY_FUNCTION__ << "Unknown column" << column;
|
|
|
|
return QString();
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-25 14:11:09 +01:00
|
|
|
static TagCompletionModel* InitCompletionModel(LibraryBackend* backend,
|
|
|
|
Playlist::Column column) {
|
|
|
|
return new TagCompletionModel(backend, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
TagCompleter::TagCompleter(LibraryBackend* backend, Playlist::Column column,
|
|
|
|
QLineEdit* editor)
|
|
|
|
: QCompleter(editor),
|
|
|
|
editor_(editor)
|
|
|
|
{
|
|
|
|
QFuture<TagCompletionModel*> future = QtConcurrent::run(
|
|
|
|
&InitCompletionModel, backend, column);
|
|
|
|
QFutureWatcher<TagCompletionModel*>* watcher =
|
|
|
|
new QFutureWatcher<TagCompletionModel*>(this);
|
|
|
|
watcher->setFuture(future);
|
|
|
|
|
|
|
|
connect(watcher, SIGNAL(finished()), SLOT(ModelReady()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TagCompleter::ModelReady() {
|
|
|
|
QFutureWatcher<TagCompletionModel*>* watcher =
|
|
|
|
dynamic_cast<QFutureWatcher<TagCompletionModel*>*>(sender());
|
|
|
|
if (!watcher)
|
|
|
|
return;
|
2010-03-29 18:59:01 +02:00
|
|
|
|
2010-12-25 14:11:09 +01:00
|
|
|
TagCompletionModel* model = watcher->result();
|
|
|
|
setModel(model);
|
2010-03-29 18:59:01 +02:00
|
|
|
setCaseSensitivity(Qt::CaseInsensitive);
|
2010-12-25 14:11:09 +01:00
|
|
|
editor_->setCompleter(this);
|
2010-03-29 18:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* TagCompletionItemDelegate::createEditor(
|
2010-05-09 02:10:26 +02:00
|
|
|
QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const {
|
2010-03-29 18:59:01 +02:00
|
|
|
|
|
|
|
QLineEdit* editor = new QLineEdit(parent);
|
2010-05-09 02:10:26 +02:00
|
|
|
new TagCompleter(backend_, column_, editor);
|
2010-03-29 18:59:01 +02:00
|
|
|
|
|
|
|
return editor;
|
|
|
|
}
|
2010-08-28 21:07:23 +02:00
|
|
|
|
|
|
|
QString NativeSeparatorsDelegate::displayText(const QVariant& value, const QLocale&) const {
|
|
|
|
QString str = value.toString();
|
|
|
|
if (str.contains("://"))
|
|
|
|
return str;
|
|
|
|
return QDir::toNativeSeparators(str);
|
|
|
|
}
|