Skip to content
Extraits de code Groupes Projets
Vérifiée Valider abcd785e rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Add the IsComment column

parent 78fd31bc
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!7Add the ASS sub document and the ASS tree
...@@ -25,8 +25,7 @@ Line::Line(AssFactory *const factory, const QString &lineString) ...@@ -25,8 +25,7 @@ Line::Line(AssFactory *const factory, const QString &lineString)
}; };
static const QString lineHeader = "Dialogue: "; static const QString lineHeader = "Dialogue: ";
if (!lineString.startsWith(lineHeader)) isComment = !lineString.startsWith(lineHeader);
throw std::runtime_error(("invalid event line header: " + lineString).toStdString());
const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */); const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */);
QStringList contentList = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive); QStringList contentList = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive);
...@@ -130,3 +129,9 @@ Line::getContent() const noexcept ...@@ -130,3 +129,9 @@ Line::getContent() const noexcept
{ {
return content; return content;
} }
bool
Line::getIsComment() const noexcept
{
return isComment;
}
...@@ -16,6 +16,7 @@ private: ...@@ -16,6 +16,7 @@ private:
quint64 start{ 0 }; quint64 start{ 0 };
quint64 end{ 0 }; quint64 end{ 0 };
int layer{ 0 }; int layer{ 0 };
bool isComment{ true };
QVector<Syl> content{}; QVector<Syl> content{};
StyleProperties styleProperties{}; StyleProperties styleProperties{};
...@@ -37,6 +38,7 @@ public: ...@@ -37,6 +38,7 @@ public:
void setStart(quint64 s) noexcept; void setStart(quint64 s) noexcept;
void setEnd(quint64 s) noexcept; void setEnd(quint64 s) noexcept;
quint64 getDuration() const noexcept; quint64 getDuration() const noexcept;
bool getIsComment() const noexcept;
StyleProperties getStyleProperties() const noexcept; StyleProperties getStyleProperties() const noexcept;
StyleWeakPtr getStyle() const noexcept; StyleWeakPtr getStyle() const noexcept;
......
...@@ -27,6 +27,14 @@ AssLinesModel::Item::getLineText() const noexcept ...@@ -27,6 +27,14 @@ AssLinesModel::Item::getLineText() const noexcept
return ret; return ret;
} }
bool
AssLinesModel::Item::getIsComment() const noexcept
{
if (auto ptr = line.lock())
return ptr->getIsComment();
return false;
}
QString QString
AssLinesModel::Item::getLineStyle() const noexcept AssLinesModel::Item::getLineStyle() const noexcept
{ {
...@@ -58,12 +66,27 @@ AssLinesModel::data(const QModelIndex &index, int role) const noexcept ...@@ -58,12 +66,27 @@ AssLinesModel::data(const QModelIndex &index, int role) const noexcept
return QVariant(); return QVariant();
const Item *line = static_cast<const Item *>(index.internalPointer()); const Item *line = static_cast<const Item *>(index.internalPointer());
const Item::Field column = static_cast<Item::Field>(index.column());
if (Qt::DisplayRole == role) { // Check state only for the IsComment
switch (static_cast<Item::Field>(index.column())) { if (role == Qt::CheckStateRole && column == Item::Field::IsComment) {
return line->getIsComment() ? Qt::Checked : Qt::Unchecked;
}
// Is comment is centered
else if (role == Qt::TextAlignmentRole && column == Item::Field::IsComment) {
return Qt::AlignCenter;
}
// Display role
else if (Qt::DisplayRole == role) {
switch (column) {
case Item::Field::Style: case Item::Field::Style:
return line->getLineStyle(); return line->getLineStyle();
case Item::Field::IsComment:
return QVariant();
case Item::Field::Text: case Item::Field::Text:
return line->getLineText(); return line->getLineText();
...@@ -144,5 +167,5 @@ Qt::ItemFlags ...@@ -144,5 +167,5 @@ Qt::ItemFlags
AssLinesModel::flags(const QModelIndex &index) const noexcept AssLinesModel::flags(const QModelIndex &index) const noexcept
{ {
[[maybe_unused]] const Item *item = static_cast<const Item *>(index.internalPointer()); [[maybe_unused]] const Item *item = static_cast<const Item *>(index.internalPointer());
return Qt::ItemIsSelectable | QAbstractItemModel::flags(index); return Qt::ItemNeverHasChildren | Qt::ItemIsSelectable | QAbstractItemModel::flags(index);
} }
...@@ -20,6 +20,7 @@ private: ...@@ -20,6 +20,7 @@ private:
~Item() noexcept = default; ~Item() noexcept = default;
enum class Field : int { enum class Field : int {
IsComment,
Style, Style,
Text, Text,
...@@ -27,6 +28,7 @@ private: ...@@ -27,6 +28,7 @@ private:
TotalFieldCount, TotalFieldCount,
}; };
bool getIsComment() const noexcept;
quint64 getLineNumber() const noexcept; quint64 getLineNumber() const noexcept;
QString getLineText() const noexcept; QString getLineText() const noexcept;
QString getLineStyle() const noexcept; QString getLineStyle() const noexcept;
...@@ -35,7 +37,7 @@ private: ...@@ -35,7 +37,7 @@ private:
Ass::LineWeakPtr line; Ass::LineWeakPtr line;
}; };
static inline const QStringList headers{ "Actor", "Text" }; static inline const QStringList headers{ "", "Actor", "Text" };
public: public:
explicit AssLinesModel(const QVector<Ass::LinePtr> &) noexcept; explicit AssLinesModel(const QVector<Ass::LinePtr> &) noexcept;
......
...@@ -86,3 +86,15 @@ AssLinesView::Delegate::onItemEntered(const QModelIndex &index) noexcept ...@@ -86,3 +86,15 @@ AssLinesView::Delegate::onItemEntered(const QModelIndex &index) noexcept
{ {
hoveredRow = index.row(); hoveredRow = index.row();
} }
void
AssLinesView::Delegate::initStyleOption(QStyleOptionViewItem *option,
const QModelIndex &index) const noexcept
{
QStyledItemDelegate::initStyleOption(option, index);
// The first column is the IsComment column
// XXX This is hardcoded
if (index.column() == 0)
option->displayAlignment = Qt::AlignCenter;
}
...@@ -25,6 +25,9 @@ private: ...@@ -25,6 +25,9 @@ private:
Delegate(AssLinesView *, QWidget *parent = nullptr) noexcept; Delegate(AssLinesView *, QWidget *parent = nullptr) noexcept;
~Delegate() noexcept = default; ~Delegate() noexcept = default;
void initStyleOption(QStyleOptionViewItem *option,
const QModelIndex &index) const noexcept override;
void paint(QPainter *, const QStyleOptionViewItem &, void paint(QPainter *, const QStyleOptionViewItem &,
const QModelIndex &) const noexcept override; const QModelIndex &) const noexcept override;
void onItemEntered(const QModelIndex &) noexcept; void onItemEntered(const QModelIndex &) noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter