Add PostWidget and put some test posts into the QTreeWidget.
This commit is contained in:
parent
32a1074bc8
commit
142cbf5ea0
|
@ -2,5 +2,6 @@
|
||||||
<RCC version="1.0">
|
<RCC version="1.0">
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file alias="AUTHORS">../AUTHORS</file>
|
<file alias="AUTHORS">../AUTHORS</file>
|
||||||
|
<file>images/no_avatar.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="585"
|
||||||
|
height="585"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.48.1 r9760"
|
||||||
|
sodipodi:docname="mm.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="0.7"
|
||||||
|
inkscape:cx="363.16555"
|
||||||
|
inkscape:cy="281.80281"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1172"
|
||||||
|
inkscape:window-height="777"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="0" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Calque 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-128.57143,-128.79074)">
|
||||||
|
<rect
|
||||||
|
style="fill:#808080;fill-opacity:1;stroke:none"
|
||||||
|
id="rect3755"
|
||||||
|
width="585"
|
||||||
|
height="585"
|
||||||
|
x="128.57143"
|
||||||
|
y="128.79074" />
|
||||||
|
<path
|
||||||
|
sodipodi:type="arc"
|
||||||
|
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||||
|
id="path2985"
|
||||||
|
sodipodi:cx="451.42856"
|
||||||
|
sodipodi:cy="329.50504"
|
||||||
|
sodipodi:rx="165.71428"
|
||||||
|
sodipodi:ry="165.71428"
|
||||||
|
d="m 617.14284,329.50504 c 0,91.52146 -74.19281,165.71427 -165.71428,165.71427 -91.52147,0 -165.71428,-74.19281 -165.71428,-165.71427 0,-91.52147 74.19281,-165.71428 165.71428,-165.71428 91.52147,0 165.71428,74.19281 165.71428,165.71428 z"
|
||||||
|
transform="translate(-30.357132,0)" />
|
||||||
|
<path
|
||||||
|
sodipodi:type="star"
|
||||||
|
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||||
|
id="path3759"
|
||||||
|
sodipodi:sides="3"
|
||||||
|
sodipodi:cx="417.14285"
|
||||||
|
sodipodi:cy="343.79074"
|
||||||
|
sodipodi:r1="330.14529"
|
||||||
|
sodipodi:r2="165.07265"
|
||||||
|
sodipodi:arg1="2.6179939"
|
||||||
|
sodipodi:arg2="3.6651914"
|
||||||
|
inkscape:flatsided="true"
|
||||||
|
inkscape:rounded="0"
|
||||||
|
inkscape:randomized="0"
|
||||||
|
d="M 131.22864,508.86338 417.14286,13.645447 703.05706,508.86339 z"
|
||||||
|
inkscape:transform-center-y="-66.822037"
|
||||||
|
transform="matrix(0.80383817,0,0,0.80960764,85.756082,301.79749)" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.9 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
/* This file is part of FediPotato.
|
||||||
|
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "widget_post.hpp"
|
||||||
|
|
||||||
|
namespace FediPotato
|
||||||
|
{
|
||||||
|
|
||||||
|
void PostWidget::show_hide_elements()
|
||||||
|
{
|
||||||
|
const bool has_subject{label_subject->text().isEmpty()};
|
||||||
|
label_subject->setHidden(has_subject);
|
||||||
|
button_more->setHidden(has_subject);
|
||||||
|
|
||||||
|
if (label_avatar->pixmap() == nullptr)
|
||||||
|
{
|
||||||
|
set_avatar(":/images/no_avatar.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FediPotato
|
|
@ -0,0 +1,66 @@
|
||||||
|
#ifndef FEDIPOTATO_GUI_WIDGET_POST_HPP
|
||||||
|
#define FEDIPOTATO_GUI_WIDGET_POST_HPP
|
||||||
|
|
||||||
|
#include "../ui/ui_widget_post.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QTreeWidget>
|
||||||
|
|
||||||
|
namespace FediPotato
|
||||||
|
{
|
||||||
|
|
||||||
|
class PostWidget : public QWidget, private Ui::PostWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Default constructor
|
||||||
|
explicit PostWidget(QWidget *parent = nullptr)
|
||||||
|
: QWidget{parent}
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Copy constructor
|
||||||
|
PostWidget(const PostWidget &other) = delete;
|
||||||
|
|
||||||
|
//! Move constructor
|
||||||
|
PostWidget(PostWidget &&other) noexcept = delete;
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~PostWidget() noexcept override = default;
|
||||||
|
|
||||||
|
//! Copy assignment operator
|
||||||
|
PostWidget& operator=(const PostWidget &other) = delete;
|
||||||
|
|
||||||
|
//! Move assignment operator
|
||||||
|
PostWidget& operator=(PostWidget &&other) noexcept = delete;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline void set_user(const QString &user)
|
||||||
|
{
|
||||||
|
label_user->setText(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_avatar(const QString &avatar)
|
||||||
|
{
|
||||||
|
label_avatar->setPixmap(QIcon(avatar).pixmap(QSize(50, 50)));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_subject(const QString &subject)
|
||||||
|
{
|
||||||
|
label_subject->setText(subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_content(const QString &content)
|
||||||
|
{
|
||||||
|
label_content->setText(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_hide_elements();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace FediPotato
|
||||||
|
|
||||||
|
#endif // FEDIPOTATO_GUI_WIDGET_POST_HPP
|
|
@ -17,6 +17,7 @@
|
||||||
#include "window_main.hpp"
|
#include "window_main.hpp"
|
||||||
#include "channel.hpp"
|
#include "channel.hpp"
|
||||||
#include "dialog_about.hpp"
|
#include "dialog_about.hpp"
|
||||||
|
#include "widget_post.hpp"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
@ -33,7 +34,53 @@ MainWindow::MainWindow(QMainWindow *parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
// Add account for testing.
|
||||||
add_account();
|
add_account();
|
||||||
|
|
||||||
|
// Add some post widgets for testing.
|
||||||
|
// FIXME: The widgets don't resize properly.
|
||||||
|
QTreeWidgetItem *item_root{treewidget_posts->invisibleRootItem()};
|
||||||
|
for (int i{0}; i < 2; ++i)
|
||||||
|
{
|
||||||
|
auto *pw1{new PostWidget(treewidget_posts)};
|
||||||
|
pw1->set_user("@user@example.com");
|
||||||
|
pw1->set_subject("Food");
|
||||||
|
pw1->set_content("I ate a whole lot of potatos today!");
|
||||||
|
pw1->set_avatar(":/images/no_avatar.svg");
|
||||||
|
pw1->show_hide_elements();
|
||||||
|
auto *item1{new QTreeWidgetItem};
|
||||||
|
item_root->addChild(item1);
|
||||||
|
treewidget_posts->setItemWidget(item1, 0, pw1);
|
||||||
|
|
||||||
|
auto *pw2{new PostWidget(treewidget_posts)};
|
||||||
|
pw2->set_user("@user@example.com");
|
||||||
|
pw2->set_subject("Pseudo-latin");
|
||||||
|
pw2->set_content("Aliquam feugiat tellus ut neque. Sed bibendum. "
|
||||||
|
"Mauris ac felis vel velit tristique imperdiet.");
|
||||||
|
pw2->show_hide_elements();
|
||||||
|
auto *item2{new QTreeWidgetItem};
|
||||||
|
item1->addChild(item2);
|
||||||
|
treewidget_posts->setItemWidget(item2, 0, pw2);
|
||||||
|
|
||||||
|
auto *pw4{new PostWidget(treewidget_posts)};
|
||||||
|
pw4->set_user("@user@example.com");
|
||||||
|
pw4->set_content("Nam vestibulum accumsan nisl. "
|
||||||
|
"Praesent fermentum tempor tellus. Fusce commodo. "
|
||||||
|
"Phasellus purus. "
|
||||||
|
"Praesent fermentum tempor tellus.");
|
||||||
|
pw4->show_hide_elements();
|
||||||
|
auto *item4{new QTreeWidgetItem};
|
||||||
|
item2->addChild(item4);
|
||||||
|
treewidget_posts->setItemWidget(item4, 0, pw4);
|
||||||
|
|
||||||
|
auto *pw3{new PostWidget(treewidget_posts)};
|
||||||
|
pw3->set_user("@user@example.com");
|
||||||
|
pw3->set_content("👍");
|
||||||
|
pw3->show_hide_elements();
|
||||||
|
auto *item3{new QTreeWidgetItem};
|
||||||
|
item1->addChild(item3);
|
||||||
|
treewidget_posts->setItemWidget(item3, 0, pw3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::add_account()
|
void MainWindow::add_account()
|
||||||
|
|
|
@ -6,24 +6,36 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>250</width>
|
<width>200</width>
|
||||||
<height>130</height>
|
<height>115</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>150</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: blue;</string>
|
||||||
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="vbox_left" stretch="0,0">
|
<layout class="QVBoxLayout" name="vbox_left" stretch="0,0">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetFixedSize</enum>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_avatar">
|
<widget class="QLabel" name="label_avatar">
|
||||||
|
@ -38,14 +50,14 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>100</width>
|
<width>50</width>
|
||||||
<height>100</height>
|
<height>50</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="baseSize">
|
<property name="baseSize">
|
||||||
<size>
|
<size>
|
||||||
<width>100</width>
|
<width>50</width>
|
||||||
<height>100</height>
|
<height>50</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -82,10 +94,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="vbox_right">
|
<layout class="QVBoxLayout" name="vbox_right">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetMinimumSize</enum>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_user">
|
<widget class="QLabel" name="label_user">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -96,6 +111,9 @@
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: green;</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -116,11 +134,14 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_subject">
|
<widget class="QLabel" name="label_subject">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: green;</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -137,6 +158,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="button_more">
|
<widget class="QPushButton" name="button_more">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Show more</string>
|
<string>Show more</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -148,7 +175,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_content">
|
<widget class="QLabel" name="label_content">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -159,6 +186,9 @@
|
||||||
<bold>false</bold>
|
<bold>false</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: green;</string>
|
||||||
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::NoFrame</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -166,7 +196,7 @@
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="textFormat">
|
<property name="textFormat">
|
||||||
<enum>Qt::RichText</enum>
|
<enum>Qt::PlainText</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
|
|
@ -37,13 +37,27 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="treeview_posts">
|
<widget class="QTreeWidget" name="treewidget_posts">
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="indentation">
|
||||||
|
<number>20</number>
|
||||||
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<attribute name="headerVisible">
|
<attribute name="headerVisible">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">1</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
Reference in New Issue