2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "shortobjectwidget.h"
23 #include <QVBoxLayout>
25 //------------------------------------------------------------------------------
27 ShortObjectWidget::ShortObjectWidget(QASObject
* obj
, QWidget
* parent
) :
33 qDebug() << "Creating ShortObjectWidget";
35 m_textLabel
= new RichTextLabel(this, true);
37 m_actorWidget
= new ActorWidget(NULL
, this, true);
38 connect(m_actorWidget
, SIGNAL(follow(QString
, bool)),
39 this, SIGNAL(follow(QString
, bool)));
40 connect(m_actorWidget
, SIGNAL(moreClicked()), this, SIGNAL(moreClicked()));
42 m_moreButton
= new TextToolButton("+", this);
43 connect(m_moreButton
, SIGNAL(clicked()), this, SIGNAL(moreClicked()));
45 QHBoxLayout
* acrossLayout
= new QHBoxLayout
;
46 // acrossLayout->setSpacing(10);
47 acrossLayout
->setContentsMargins(0, 0, 0, 0);
48 acrossLayout
->addWidget(m_actorWidget
, 0, Qt::AlignVCenter
);
49 acrossLayout
->addWidget(m_textLabel
, 0, Qt::AlignVCenter
);
50 acrossLayout
->addWidget(m_moreButton
, 0, Qt::AlignVCenter
);
54 setLayout(acrossLayout
);
57 //------------------------------------------------------------------------------
59 ShortObjectWidget::~ShortObjectWidget() {
61 qDebug() << "Deleting ShortObjectWidget" << m_object
->id();
65 //------------------------------------------------------------------------------
67 void ShortObjectWidget::changeObject(QASAbstractObject
* obj
) {
69 disconnect(m_object
, SIGNAL(changed()), this, SLOT(onChanged()));
71 m_object
= qobject_cast
<QASObject
*>(obj
);
75 connect(m_object
, SIGNAL(changed()), this, SLOT(onChanged()));
78 disconnect(m_actor
, SIGNAL(changed()),
79 m_actorWidget
, SLOT(updateMenu()));
81 QASActor
* m_actor
= m_object
->asActor();
83 m_actor
= m_object
->author();
85 connect(m_actor
, SIGNAL(changed()),
86 m_actorWidget
, SLOT(updateMenu()));
88 m_actorWidget
->setActor(m_actor
);
90 static QSet
<QString
> expandableTypes
;
91 if (expandableTypes
.isEmpty())
92 expandableTypes
<< "person" << "note" << "comment" << "image" << "video"
95 m_moreButton
->setVisible(expandableTypes
.contains(m_object
->type())
96 && !m_object
->isDeleted());
101 //------------------------------------------------------------------------------
103 void ShortObjectWidget::updateText() {
107 QString content
= m_object
->excerpt();
110 QASActor
* author
= m_object
->author();
111 if (author
&& !author
->displayName().isEmpty())
112 text
= author
->displayName();
113 if (!content
.isEmpty())
114 text
+= (text
.isEmpty() ? "" : ": ") + content
;
116 m_textLabel
->setText(text
);
119 //------------------------------------------------------------------------------
121 void ShortObjectWidget::onChanged() {
123 m_actorWidget
->updateMenu();
126 //------------------------------------------------------------------------------