• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6685397774

29 Oct 2023 07:37PM UTC coverage: 11.735% (-0.002%) from 11.737%
6685397774

push

github

10110111
Deduplicate title bar implementation

131 of 131 new or added lines in 56 files covered. (100.0%)

14842 of 126472 relevant lines covered (11.74%)

21617.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/gui/Dialog.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2008 Guillaume Chereau
4
 * 
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 * 
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 * 
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
18
 */
19

20
#include <QDebug>
21

22
#include "Dialog.hpp"
23
#include <QHBoxLayout>
24
#include "StelMainView.hpp"
25
#include "StelCloseButton.hpp"
26

27
TitleBar::TitleBar(QWidget* parent)
×
28
        : QFrame(parent)
29
        , label(new QLabel("unnamed window"))
×
30
{
31
        setFrameStyle(QFrame::StyledPanel);
×
32

33
        const auto layout = new QHBoxLayout(this);
×
34

35
        label->setObjectName("stelWindowTitle");
×
36
        label->setAlignment(Qt::AlignCenter);
×
37
        label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
×
38
        layout->addWidget(label);
×
39
        layout->setContentsMargins(0,0,0,0);
×
40

41
        const auto close = new StelCloseButton;
×
42
        close->setFocusPolicy(Qt::NoFocus);
×
43
        layout->addWidget(close);
×
44

45
        connect(close, &QAbstractButton::clicked, this, &TitleBar::closeClicked);
×
46
}
×
47

48
void TitleBar::mousePressEvent(QMouseEvent *event)
×
49
{
50
        mousePos = event->pos();
×
51
        moving = true;
×
52
}
×
53

54
void TitleBar::mouseReleaseEvent(QMouseEvent *)
×
55
{
56
        moving = false;
×
57
        QWidget* p = dynamic_cast<QWidget*>(QFrame::parent());
×
58
        emit movedTo(p->pos());
×
59
}
×
60

61
void TitleBar::mouseMoveEvent(QMouseEvent *event)
×
62
{
63
        if (!moving) return;
×
64
        QPoint dpos = event->pos() - mousePos;
×
65
        QWidget* p = dynamic_cast<QWidget*>(QFrame::parent());
×
66
        QPoint targetPos = p->pos() + dpos;
×
67
        
68
        QWidget *parent=parentWidget();
×
69
        Q_ASSERT(parent);
×
70

71
        if (!(parent->inherits("CustomDialog")))
×
72
        {
73
                // Prevent the title bar from being dragged to an unreachable position.
74
                QWidget& mainWindow = StelMainView::getInstance();
×
75
                int leftBoundX = 10 - width();
×
76
                int rightBoundX = mainWindow.width() - 10;
×
77
                if (targetPos.x() < leftBoundX)
×
78
                        targetPos.setX(leftBoundX);
×
79
                else if (targetPos.x() > rightBoundX)
×
80
                        targetPos.setX(rightBoundX);
×
81

82
                int lowerBoundY = mainWindow.height() - height();
×
83
                if (targetPos.y() < 0)
×
84
                        targetPos.setY(0);
×
85
                else if (targetPos.y() > lowerBoundY)
×
86
                        targetPos.setY(lowerBoundY);
×
87
        }
88
        p->move(targetPos);
×
89
        //emit movedTo(targetPos);
90
}
91

92
void ResizeFrame::mouseMoveEvent(QMouseEvent *event)
×
93
{
94
        QPoint dpos = event->pos() - mousePos;
×
95
        QWidget* p = dynamic_cast<QWidget*>(QFrame::parent()->parent());
×
96
        if (p!=Q_NULLPTR)
×
97
        {
98
                int w = p->size().width();
×
99
                int h = p->size().height();
×
100
                int minw;
101
                int minh;
102

103
                if (p->minimumSizeHint().isValid())
×
104
                {
105
                        minw = p->minimumSizeHint().width();
×
106
                        minh = p->minimumSizeHint().height();
×
107
                }
108
                else
109
                {
110
                        minw = p->minimumWidth() > 0 ? p->minimumWidth() : 24;
×
111
                        minh = p->minimumHeight() > 0 ? p->minimumHeight() : 24;
×
112
                }
113

114
                // The minimum size will only be enforced if the widget is being
115
                // shrunk, and its size is larger than its minimum size. (If, for some
116
                // reason, the widget's size is already *smaller* than its minimum
117
                // size, and the user is actually trying to *shrink* it, then it would
118
                // be rather odd to *enlarge* the widget to its minimum size.)
119
                if (w + dpos.x() >= minw)
×
120
                        w += dpos.x();
×
121
                else if (w > minw && dpos.x() < 0)
×
122
                        w = minw;
×
123
                if (h + dpos.y() >= minh)
×
124
                        h += dpos.y();
×
125
                else if (h > minh && dpos.y() < 0)
×
126
                        h = minh;
×
127

128
                p->setUpdatesEnabled(false);
×
129
                p->resize(w, h);
×
130
                p->setUpdatesEnabled(true);
×
131
        }
132
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc