mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
parent
f4df262179
commit
a4533ae92c
|
@ -50,6 +50,8 @@ std::pair<int, int> NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||||
auto it = std::find(std::begin(this->chatWidgets), std::end(this->chatWidgets), widget);
|
auto it = std::find(std::begin(this->chatWidgets), std::end(this->chatWidgets), widget);
|
||||||
if (it != std::end(this->chatWidgets)) {
|
if (it != std::end(this->chatWidgets)) {
|
||||||
this->chatWidgets.erase(it);
|
this->chatWidgets.erase(it);
|
||||||
|
|
||||||
|
this->refreshTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove from box and return location
|
// remove from box and return location
|
||||||
|
@ -82,6 +84,9 @@ void NotebookPage::addToLayout(ChatWidget *widget,
|
||||||
std::pair<int, int> position = std::pair<int, int>(-1, -1))
|
std::pair<int, int> position = std::pair<int, int>(-1, -1))
|
||||||
{
|
{
|
||||||
this->chatWidgets.push_back(widget);
|
this->chatWidgets.push_back(widget);
|
||||||
|
|
||||||
|
this->refreshTitle();
|
||||||
|
|
||||||
widget->giveFocus(Qt::MouseFocusReason);
|
widget->giveFocus(Qt::MouseFocusReason);
|
||||||
|
|
||||||
// add vbox at the end
|
// add vbox at the end
|
||||||
|
@ -404,6 +409,27 @@ ChatWidget *NotebookPage::createChatWidget()
|
||||||
return new ChatWidget(this->channelManager, this);
|
return new ChatWidget(this->channelManager, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotebookPage::refreshTitle()
|
||||||
|
{
|
||||||
|
if (!this->tab->useDefaultBehaviour) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString newTitle = "";
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
|
for (const auto &chatWidget : this->chatWidgets) {
|
||||||
|
if (!first) {
|
||||||
|
newTitle += ", ";
|
||||||
|
}
|
||||||
|
newTitle += QString::fromStdString(chatWidget->channelName.getValue());
|
||||||
|
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->tab->setTitle(newTitle);
|
||||||
|
}
|
||||||
|
|
||||||
void NotebookPage::load(const boost::property_tree::ptree &tree)
|
void NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -98,6 +98,8 @@ private:
|
||||||
ChatWidget *createChatWidget();
|
ChatWidget *createChatWidget();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void refreshTitle();
|
||||||
|
|
||||||
void load(const boost::property_tree::ptree &tree);
|
void load(const boost::property_tree::ptree &tree);
|
||||||
boost::property_tree::ptree save();
|
boost::property_tree::ptree save();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
#include "colorscheme.hpp"
|
#include "colorscheme.hpp"
|
||||||
#include "settingsmanager.hpp"
|
#include "settingsmanager.hpp"
|
||||||
#include "widgets/notebook.hpp"
|
#include "widgets/notebook.hpp"
|
||||||
|
#include "widgets/textinputdialog.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -12,6 +14,7 @@ NotebookTab::NotebookTab(Notebook *_notebook)
|
||||||
: BaseWidget(_notebook)
|
: BaseWidget(_notebook)
|
||||||
, positionChangedAnimation(this, "pos")
|
, positionChangedAnimation(this, "pos")
|
||||||
, notebook(_notebook)
|
, notebook(_notebook)
|
||||||
|
, menu(this)
|
||||||
{
|
{
|
||||||
this->calcSize();
|
this->calcSize();
|
||||||
this->setAcceptDrops(true);
|
this->setAcceptDrops(true);
|
||||||
|
@ -22,6 +25,37 @@ NotebookTab::NotebookTab(Notebook *_notebook)
|
||||||
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
|
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
|
||||||
|
|
||||||
this->setMouseTracking(true);
|
this->setMouseTracking(true);
|
||||||
|
|
||||||
|
this->menu.addAction("Rename", [this]() {
|
||||||
|
TextInputDialog d(this);
|
||||||
|
|
||||||
|
d.setWindowTitle("Change tab title (Leave empty for default behaviour)");
|
||||||
|
if (this->useDefaultBehaviour) {
|
||||||
|
d.setText("");
|
||||||
|
} else {
|
||||||
|
d.setText(this->getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d.exec() == QDialog::Accepted) {
|
||||||
|
QString newTitle = d.getText();
|
||||||
|
if (newTitle.isEmpty()) {
|
||||||
|
this->useDefaultBehaviour = true;
|
||||||
|
this->page->refreshTitle();
|
||||||
|
} else {
|
||||||
|
this->useDefaultBehaviour = false;
|
||||||
|
this->setTitle(newTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this->menu.addAction("Close", [=]() {
|
||||||
|
// this->notebook->removePage(this->page); //
|
||||||
|
qDebug() << "TODO: Implement"; //
|
||||||
|
});
|
||||||
|
|
||||||
|
this->menu.addAction("Enable highlights on new message", []() {
|
||||||
|
qDebug() << "TODO: Implement"; //
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
NotebookTab::~NotebookTab()
|
NotebookTab::~NotebookTab()
|
||||||
|
@ -50,6 +84,8 @@ const QString &NotebookTab::getTitle() const
|
||||||
void NotebookTab::setTitle(const QString &newTitle)
|
void NotebookTab::setTitle(const QString &newTitle)
|
||||||
{
|
{
|
||||||
this->title = newTitle;
|
this->title = newTitle;
|
||||||
|
|
||||||
|
this->calcSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotebookTab::isSelected() const
|
bool NotebookTab::isSelected() const
|
||||||
|
@ -163,7 +199,17 @@ void NotebookTab::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
||||||
this->update();
|
this->update();
|
||||||
|
|
||||||
this->notebook->select(page);
|
switch (event->button()) {
|
||||||
|
case Qt::LeftButton: {
|
||||||
|
this->notebook->select(page);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Qt::RightButton: {
|
||||||
|
this->notebook->select(page);
|
||||||
|
|
||||||
|
this->menu.popup(event->globalPos());
|
||||||
|
} break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
@ -229,7 +275,13 @@ void NotebookTab::load(const boost::property_tree::ptree &tree)
|
||||||
{
|
{
|
||||||
// Load tab title
|
// Load tab title
|
||||||
try {
|
try {
|
||||||
this->setTitle(QString::fromStdString(tree.get<std::string>("title")));
|
QString newTitle = QString::fromStdString(tree.get<std::string>("title"));
|
||||||
|
if (newTitle.isEmpty()) {
|
||||||
|
this->useDefaultBehaviour = true;
|
||||||
|
} else {
|
||||||
|
this->setTitle(newTitle);
|
||||||
|
this->useDefaultBehaviour = false;
|
||||||
|
}
|
||||||
} catch (boost::property_tree::ptree_error) {
|
} catch (boost::property_tree::ptree_error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +290,11 @@ boost::property_tree::ptree NotebookTab::save()
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree tree;
|
boost::property_tree::ptree tree;
|
||||||
|
|
||||||
tree.put("title", this->getTitle().toStdString());
|
if (this->useDefaultBehaviour) {
|
||||||
|
tree.put("title", "");
|
||||||
|
} else {
|
||||||
|
tree.put("title", this->getTitle().toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "widgets/basewidget.hpp"
|
#include "widgets/basewidget.hpp"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/signals2.hpp>
|
#include <boost/signals2.hpp>
|
||||||
|
@ -64,8 +65,12 @@ private:
|
||||||
|
|
||||||
Notebook *notebook;
|
Notebook *notebook;
|
||||||
|
|
||||||
QString title = "<no title>";
|
QString title;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool useDefaultBehaviour = true;
|
||||||
|
|
||||||
|
private:
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
bool mouseOver = false;
|
bool mouseOver = false;
|
||||||
bool mouseDown = false;
|
bool mouseDown = false;
|
||||||
|
@ -74,6 +79,8 @@ private:
|
||||||
|
|
||||||
HighlightStyle highlightStyle = HighlightStyle::HighlightNone;
|
HighlightStyle highlightStyle = HighlightStyle::HighlightNone;
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
|
||||||
QRect getXRect()
|
QRect getXRect()
|
||||||
{
|
{
|
||||||
return QRect(this->width() - 20, 4, 16, 16);
|
return QRect(this->width() - 20, 4, 16, 16);
|
||||||
|
|
Loading…
Reference in a new issue