documentation and folded item delegates from old code back in
This commit is contained in:
@@ -24,7 +24,13 @@ set(OLIVE_SOURCES
|
||||
widget/projectexplorer/projectexplorerlistview.cpp
|
||||
widget/projectexplorer/projectexplorerlistviewbase.h
|
||||
widget/projectexplorer/projectexplorerlistviewbase.cpp
|
||||
widget/projectexplorer/projectexplorerlistviewitemdelegate.h
|
||||
widget/projectexplorer/projectexplorerlistviewitemdelegate.cpp
|
||||
widget/projectexplorer/projectexplorericonview.h
|
||||
widget/projectexplorer/projectexplorericonview.cpp
|
||||
widget/projectexplorer/projectexplorericonviewitemdelegate.h
|
||||
widget/projectexplorer/projectexplorericonviewitemdelegate.cpp
|
||||
widget/projectexplorer/projectexplorernavigation.h
|
||||
widget/projectexplorer/projectexplorernavigation.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -46,8 +46,18 @@ void ProjectExplorer::set_view_type(olive::ProjectViewType type)
|
||||
{
|
||||
view_type_ = type;
|
||||
|
||||
// Enum values correspond to the index of the widget in this stacked widget
|
||||
setCurrentIndex(view_type_);
|
||||
// Set widget based on view type
|
||||
switch (view_type_) {
|
||||
case olive::TreeView:
|
||||
setCurrentWidget(tree_view_);
|
||||
break;
|
||||
case olive::ListView:
|
||||
setCurrentWidget(list_view_);
|
||||
break;
|
||||
case olive::IconView:
|
||||
setCurrentWidget(icon_view_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::AddView(QAbstractItemView *view)
|
||||
|
||||
@@ -24,4 +24,6 @@ ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent) :
|
||||
ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::IconMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
@@ -22,12 +22,16 @@
|
||||
#define PROJECTEXPLORERICONVIEW_H
|
||||
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorericonviewitemdelegate.h"
|
||||
|
||||
class ProjectExplorerIconView : public ProjectExplorerListViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerIconView(QWidget* parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerIconViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
#endif // PROJECTEXPLORERICONVIEW_H
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "projectexplorericonviewitemdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate (parent)
|
||||
{
|
||||
}
|
||||
|
||||
QSize ProjectExplorerIconViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
|
||||
return QSize(256, 256);
|
||||
}
|
||||
|
||||
void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
|
||||
// Draw Text
|
||||
if (fm.height() < option.rect.height() / 2) {
|
||||
img_rect.setHeight(img_rect.height()-fm.height());
|
||||
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setTop(text_rect.top() + option.rect.height() - fm.height());
|
||||
|
||||
QColor text_bgcolor;
|
||||
QColor text_fgcolor;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
text_bgcolor = option.palette.highlight().color();
|
||||
text_fgcolor = option.palette.highlightedText().color();
|
||||
} else {
|
||||
text_bgcolor = Qt::white;
|
||||
text_fgcolor = Qt::black;
|
||||
}
|
||||
|
||||
painter->fillRect(text_rect, text_bgcolor);
|
||||
painter->setPen(text_fgcolor);
|
||||
|
||||
QString duration_str = index.data(Qt::UserRole).toString();
|
||||
int timecode_width = fm.width(duration_str);
|
||||
int max_name_width = option.rect.width();
|
||||
|
||||
if (timecode_width < option.rect.width() / 2) {
|
||||
painter->drawText(text_rect, Qt::AlignBottom | Qt::AlignRight, index.data(Qt::UserRole).toString());
|
||||
max_name_width -= timecode_width;
|
||||
}
|
||||
|
||||
painter->drawText(text_rect,
|
||||
Qt::AlignBottom | Qt::AlignLeft,
|
||||
fm.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, max_name_width));
|
||||
|
||||
}
|
||||
|
||||
// Draw image
|
||||
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
QSize icon_size = ico.actualSize(img_rect.size());
|
||||
img_rect = QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
|
||||
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
|
||||
icon_size.width(),
|
||||
icon_size.height());
|
||||
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
QColor highlight_color = option.palette.highlight().color();
|
||||
highlight_color.setAlphaF(0.5);
|
||||
|
||||
painter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
||||
painter->fillRect(img_rect, highlight_color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
#define PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class ProjectExplorerIconViewItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ProjectExplorerIconViewItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
#endif // PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
@@ -24,4 +24,6 @@ ProjectExplorerListView::ProjectExplorerListView(QWidget *parent) :
|
||||
ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::ListMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
@@ -22,12 +22,16 @@
|
||||
#define PROJECTEXPLORERLISTVIEW_H
|
||||
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorerlistviewitemdelegate.h"
|
||||
|
||||
class ProjectExplorerListView : public ProjectExplorerListViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerListView(QWidget* parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerListViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
#endif // PROJECTEXPLORERLISTVIEW_H
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "projectexplorerlistviewitemdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
ProjectExplorerListViewItemDelegate::ProjectExplorerListViewItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSize ProjectExplorerListViewItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
return QSize(option.decorationSize.height(), option.decorationSize.height());
|
||||
}
|
||||
|
||||
void ProjectExplorerListViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
}
|
||||
|
||||
img_rect.setWidth(qMin(img_rect.width(), img_rect.height()));
|
||||
|
||||
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
QSize icon_size = ico.actualSize(img_rect.size());
|
||||
img_rect = QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
|
||||
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
|
||||
icon_size.width(),
|
||||
icon_size.height());
|
||||
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
|
||||
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setLeft(text_rect.left() + option.rect.height());
|
||||
|
||||
int maximum_line_count = qMax(1, option.rect.height() / fm.height() - 1);
|
||||
QString text;
|
||||
if (maximum_line_count == 1) {
|
||||
text = index.data(Qt::DisplayRole).toString();
|
||||
} else {
|
||||
text = index.data(Qt::ToolTipRole).toString();
|
||||
if (text.isEmpty()) {
|
||||
text = index.data(Qt::DisplayRole).toString();
|
||||
} else {
|
||||
QStringList strings = text.split("\n");
|
||||
while (strings.size() > maximum_line_count) {
|
||||
strings.removeLast();
|
||||
}
|
||||
text = strings.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
painter->setPen(option.state & QStyle::State_Selected ?
|
||||
option.palette.highlightedText().color() : option.palette.text().color());
|
||||
|
||||
painter->drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, text);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
#define PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class ProjectExplorerListViewItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
ProjectExplorerListViewItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
#endif // PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "projectexplorernavigation.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
|
||||
dir_up_btn_ = new QPushButton(this);
|
||||
dir_up_btn_->setIcon(olive::icon::DirUp);
|
||||
layout->addWidget(dir_up_btn_);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
#define PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class ProjectExplorerNavigation : public QWidget
|
||||
{
|
||||
public:
|
||||
ProjectExplorerNavigation(QWidget* parent);
|
||||
|
||||
private:
|
||||
QPushButton* dir_up_btn_;
|
||||
};
|
||||
|
||||
#endif // PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
Reference in New Issue
Block a user