changed notation
This commit is contained in:
+43
-42
@@ -14,9 +14,9 @@ std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1);
|
||||
|
||||
NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
|
||||
: QWidget(parent)
|
||||
, m_parentbox(this)
|
||||
, m_preview(this)
|
||||
, m_chatWidgets()
|
||||
, parentbox(this)
|
||||
, preview(this)
|
||||
, chatWidgets()
|
||||
{
|
||||
this->tab = tab;
|
||||
tab->page = this;
|
||||
@@ -24,27 +24,28 @@ NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
|
||||
setHidden(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
m_parentbox.addSpacing(2);
|
||||
m_parentbox.addLayout(&m_hbox);
|
||||
m_parentbox.setMargin(0);
|
||||
this->parentbox.addSpacing(2);
|
||||
this->parentbox.addLayout(&this->hbox);
|
||||
this->parentbox.setMargin(0);
|
||||
|
||||
m_hbox.setSpacing(1);
|
||||
m_hbox.setMargin(0);
|
||||
this->hbox.setSpacing(1);
|
||||
this->hbox.setMargin(0);
|
||||
}
|
||||
|
||||
std::pair<int, int>
|
||||
NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||
{
|
||||
for (auto it = m_chatWidgets.begin(); it != m_chatWidgets.end(); ++it) {
|
||||
for (auto it = this->chatWidgets.begin(); it != this->chatWidgets.end();
|
||||
++it) {
|
||||
if (*it == widget) {
|
||||
m_chatWidgets.erase(it);
|
||||
this->chatWidgets.erase(it);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(m_hbox.itemAt(i));
|
||||
for (int i = 0; i < this->hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(i));
|
||||
|
||||
for (int j = 0; j < vbox->count(); ++j) {
|
||||
if (vbox->itemAt(j)->widget() != widget)
|
||||
@@ -55,7 +56,7 @@ NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||
bool isLastItem = vbox->count() == 0;
|
||||
|
||||
if (isLastItem) {
|
||||
m_hbox.removeItem(vbox);
|
||||
this->hbox.removeItem(vbox);
|
||||
|
||||
delete vbox;
|
||||
}
|
||||
@@ -72,14 +73,14 @@ NotebookPage::addToLayout(
|
||||
ChatWidget *widget,
|
||||
std::pair<int, int> position = std::pair<int, int>(-1, -1))
|
||||
{
|
||||
m_chatWidgets.push_back(widget);
|
||||
this->chatWidgets.push_back(widget);
|
||||
|
||||
// add vbox at the end
|
||||
if (position.first < 0 || position.first >= m_hbox.count()) {
|
||||
if (position.first < 0 || position.first >= this->hbox.count()) {
|
||||
auto vbox = new QVBoxLayout();
|
||||
vbox->addWidget(widget);
|
||||
|
||||
m_hbox.addLayout(vbox);
|
||||
this->hbox.addLayout(vbox);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,12 +89,12 @@ NotebookPage::addToLayout(
|
||||
auto vbox = new QVBoxLayout();
|
||||
vbox->addWidget(widget);
|
||||
|
||||
m_hbox.insertLayout(position.first, vbox);
|
||||
this->hbox.insertLayout(position.first, vbox);
|
||||
return;
|
||||
}
|
||||
|
||||
// add to existing vbox
|
||||
auto vbox = static_cast<QVBoxLayout *>(m_hbox.itemAt(position.first));
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(position.first));
|
||||
|
||||
vbox->insertWidget(std::max(0, std::min(vbox->count(), position.second)),
|
||||
widget);
|
||||
@@ -102,7 +103,7 @@ NotebookPage::addToLayout(
|
||||
void
|
||||
NotebookPage::enterEvent(QEvent *)
|
||||
{
|
||||
if (m_hbox.count() == 0) {
|
||||
if (this->hbox.count() == 0) {
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
} else {
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
@@ -117,7 +118,7 @@ NotebookPage::leaveEvent(QEvent *)
|
||||
void
|
||||
NotebookPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
if (this->hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
|
||||
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
@@ -131,27 +132,27 @@ NotebookPage::dragEnterEvent(QDragEnterEvent *event)
|
||||
return;
|
||||
|
||||
if (isDraggingSplit) {
|
||||
m_dropRegions.clear();
|
||||
this->dropRegions.clear();
|
||||
|
||||
if (m_hbox.count() == 0) {
|
||||
m_dropRegions.push_back(
|
||||
if (this->hbox.count() == 0) {
|
||||
this->dropRegions.push_back(
|
||||
DropRegion(rect(), std::pair<int, int>(-1, -1)));
|
||||
} else {
|
||||
for (int i = 0; i < m_hbox.count() + 1; ++i) {
|
||||
m_dropRegions.push_back(DropRegion(
|
||||
QRect(((i * 4 - 1) * width() / m_hbox.count()) / 4, 0,
|
||||
width() / m_hbox.count() / 2, height()),
|
||||
for (int i = 0; i < this->hbox.count() + 1; ++i) {
|
||||
this->dropRegions.push_back(DropRegion(
|
||||
QRect(((i * 4 - 1) * width() / this->hbox.count()) / 4, 0,
|
||||
width() / this->hbox.count() / 2, height()),
|
||||
std::pair<int, int>(i, -1)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(m_hbox.itemAt(i));
|
||||
for (int i = 0; i < this->hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(i));
|
||||
|
||||
for (int j = 0; j < vbox->count() + 1; ++j) {
|
||||
m_dropRegions.push_back(DropRegion(
|
||||
QRect(i * width() / m_hbox.count(),
|
||||
this->dropRegions.push_back(DropRegion(
|
||||
QRect(i * width() / this->hbox.count(),
|
||||
((j * 2 - 1) * height() / vbox->count()) / 2,
|
||||
width() / m_hbox.count(),
|
||||
width() / this->hbox.count(),
|
||||
height() / vbox->count()),
|
||||
std::pair<int, int>(i, j)));
|
||||
}
|
||||
@@ -173,20 +174,20 @@ NotebookPage::dragMoveEvent(QDragMoveEvent *event)
|
||||
void
|
||||
NotebookPage::setPreviewRect(QPoint mousePos)
|
||||
{
|
||||
for (DropRegion region : m_dropRegions) {
|
||||
for (DropRegion region : this->dropRegions) {
|
||||
if (region.rect.contains(mousePos)) {
|
||||
m_preview.setBounds(region.rect);
|
||||
// m_preview.move(region.rect.x(), region.rect.y());
|
||||
// m_preview.resize(region.rect.width(),
|
||||
this->preview.setBounds(region.rect);
|
||||
// this->preview.move(region.rect.x(), region.rect.y());
|
||||
// this->preview.resize(region.rect.width(),
|
||||
// region.rect.height());
|
||||
m_preview.show();
|
||||
m_preview.raise();
|
||||
this->preview.show();
|
||||
this->preview.raise();
|
||||
|
||||
dropPosition = region.position;
|
||||
|
||||
return;
|
||||
} else {
|
||||
m_preview.hide();
|
||||
this->preview.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,7 +195,7 @@ NotebookPage::setPreviewRect(QPoint mousePos)
|
||||
void
|
||||
NotebookPage::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
m_preview.hide();
|
||||
this->preview.hide();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -208,7 +209,7 @@ NotebookPage::dropEvent(QDropEvent *event)
|
||||
addToLayout(NotebookPage::draggingSplit, dropPosition);
|
||||
}
|
||||
|
||||
m_preview.hide();
|
||||
this->preview.hide();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -216,7 +217,7 @@ NotebookPage::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
if (m_hbox.count() == 0) {
|
||||
if (this->hbox.count() == 0) {
|
||||
painter.fillRect(rect(), ColorScheme::instance().ChatBackground);
|
||||
|
||||
painter.fillRect(0, 0, width(), 2,
|
||||
|
||||
Reference in New Issue
Block a user