Skip to content

Commit

Permalink
chore(#47):
Browse files Browse the repository at this point in the history
  • Loading branch information
ffiirree committed Mar 15, 2024
1 parent 19f9428 commit 7067dfb
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/capturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void Capturer::PreviewMimeData(const std::shared_ptr<QMimeData>& mimedata)
.contains(QFileInfo(mimedata->urls()[0].fileName()).suffix(), Qt::CaseInsensitive)) {

preview = new VideoPlayer();
dynamic_cast<VideoPlayer *>(preview)->open(mimedata->urls()[0].toLocalFile().toStdString(), {});
dynamic_cast<VideoPlayer *>(preview)->open(mimedata->urls()[0].toLocalFile().toStdString());
dynamic_cast<VideoPlayer *>(preview)->start();

mimedata->setData(clipboard::MIME_TYPE_STATUS, "P");
Expand Down
18 changes: 9 additions & 9 deletions src/common/selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,20 @@ void Selector::registerShortcuts()

// resize
// expand 1 pixel
connect(new QShortcut(Qt::CTRL + Qt::Key_Up, this), &QShortcut::activated, [this] { margins(-1, 0, 0, 0); });
connect(new QShortcut(Qt::CTRL + Qt::Key_Down, this), &QShortcut::activated, [this] { margins(0, 0, +1, 0); });
connect(new QShortcut(Qt::CTRL + Qt::Key_Left, this), &QShortcut::activated, [this] { margins(0, 0, 0, -1); });
connect(new QShortcut(Qt::CTRL + Qt::Key_Right, this), &QShortcut::activated, [this] { margins(0, +1, 0, 0); });
connect(new QShortcut(Qt::CTRL | Qt::Key_Up, this), &QShortcut::activated, [this] { margins(-1, 0, 0, 0); });
connect(new QShortcut(Qt::CTRL | Qt::Key_Down, this), &QShortcut::activated, [this] { margins(0, 0, +1, 0); });
connect(new QShortcut(Qt::CTRL | Qt::Key_Left, this), &QShortcut::activated, [this] { margins(0, 0, 0, -1); });
connect(new QShortcut(Qt::CTRL | Qt::Key_Right, this), &QShortcut::activated, [this] { margins(0, +1, 0, 0); });

// shrink 1 pixel
connect(new QShortcut(Qt::SHIFT + Qt::Key_Up, this), &QShortcut::activated, [this] { margins(+1, 0, 0, 0); });
connect(new QShortcut(Qt::SHIFT + Qt::Key_Down, this), &QShortcut::activated, [this] { margins(0, 0, -1, 0); });
connect(new QShortcut(Qt::SHIFT + Qt::Key_Left, this), &QShortcut::activated, [this] { margins(0, 0, 0, +1); });
connect(new QShortcut(Qt::SHIFT + Qt::Key_Right,this), &QShortcut::activated, [this] { margins(0, -1, 0, 0); });
connect(new QShortcut(Qt::SHIFT | Qt::Key_Up, this), &QShortcut::activated, [this] { margins(+1, 0, 0, 0); });
connect(new QShortcut(Qt::SHIFT | Qt::Key_Down, this), &QShortcut::activated, [this] { margins(0, 0, -1, 0); });
connect(new QShortcut(Qt::SHIFT | Qt::Key_Left, this), &QShortcut::activated, [this] { margins(0, 0, 0, +1); });
connect(new QShortcut(Qt::SHIFT | Qt::Key_Right,this), &QShortcut::activated, [this] { margins(0, -1, 0, 0); });
// clang-format on

// fullscreen
connect(new QShortcut(Qt::CTRL + Qt::Key_A, this), &QShortcut::activated, [this] {
connect(new QShortcut(Qt::CTRL | Qt::Key_A, this), &QShortcut::activated, [this] {
if (status_ <= SelectorStatus::CAPTURED &&
((prey_.type != hunter::prey_type_t::desktop) ||
(prey_.type != hunter::prey_type_t::display && scope_ == scope_t::display))) {
Expand Down
9 changes: 3 additions & 6 deletions src/player/video-player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)
initContextMenu();
}

int VideoPlayer::open(const std::string& filename, std::map<std::string, std::string>)
int VideoPlayer::open(const std::string& filename)
{
filename_ = filename;
const QFileInfo file(QString::fromStdString(filename_));
Expand Down Expand Up @@ -257,11 +257,8 @@ uint32_t VideoPlayer::audio_callback(uint8_t **ptr, const uint32_t request_frame

// update audio clock pts
if (frame.value()->pts >= 0)
audio_pts_ = av::clock::ns(frame.value()->pts, source_->afo.time_base);

if (audio_pts_.load() != av::clock::nopts)
audio_pts_ =
audio_pts_.load() + av::clock::ns(frame.value()->nb_samples, source_->afo.time_base);
av::clock::ns(frame.value()->pts + frame.value()->nb_samples, source_->afo.time_base);

sonic_stream_write(sonic_stream_, frame.value()->data[0], frame.value()->nb_samples);
}
Expand Down Expand Up @@ -529,7 +526,7 @@ void VideoPlayer::initContextMenu()
menu_->addSeparator();

addAction(menu_->addAction(tr("Properties"), this, &VideoPlayer::showProperties,
QKeySequence(Qt::CTRL + Qt::Key_I)));
QKeySequence(Qt::CTRL | Qt::Key_I)));
}

void VideoPlayer::contextMenuEvent(QContextMenuEvent *event)
Expand Down
2 changes: 1 addition & 1 deletion src/player/video-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VideoPlayer final : public FramelessWindow
~VideoPlayer() override;

// open the file & playback
int open(const std::string& filename, std::map<std::string, std::string> options);
int open(const std::string& filename);

int start();

Expand Down
8 changes: 4 additions & 4 deletions src/snipping/screenshoter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void ScreenShoter::setStyle(const SelectorStyle& style)

void ScreenShoter::registerShortcuts()
{
connect(new QShortcut(Qt::CTRL + Qt::Key_S, this), &QShortcut::activated, [this] {
connect(new QShortcut(Qt::CTRL | Qt::Key_S, this), &QShortcut::activated, [this] {
if (any(selector_->status() & SelectorStatus::CAPTURED) ||
any(selector_->status() & SelectorStatus::LOCKED)) {
save();
Expand Down Expand Up @@ -515,8 +515,8 @@ void ScreenShoter::registerShortcuts()
connect(new QShortcut(Qt::Key_Enter, this), &QShortcut::activated, [this] { copy(); exit(); });
connect(new QShortcut(Qt::Key_Escape, this), &QShortcut::activated, [this] { exit(); });

connect(new QShortcut(Qt::CTRL + Qt::Key_Z, this), &QShortcut::activated, undo_stack_, &QUndoStack::undo);
connect(new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z, this), &QShortcut::activated, undo_stack_, &QUndoStack::redo);
connect(new QShortcut(Qt::CTRL | Qt::Key_Z, this), &QShortcut::activated, undo_stack_, &QUndoStack::undo);
connect(new QShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z, this), &QShortcut::activated, undo_stack_, &QUndoStack::redo);
// clang-format on

connect(new QShortcut(QKeySequence::Delete, this), &QShortcut::activated, [this] {
Expand All @@ -543,7 +543,7 @@ void ScreenShoter::registerShortcuts()
}
});

connect(new QShortcut(Qt::CTRL + Qt::Key_C, this), &QShortcut::activated, [=, this] {
connect(new QShortcut(Qt::CTRL | Qt::Key_C, this), &QShortcut::activated, [=, this] {
if (selector_->status() < SelectorStatus::CAPTURED && magnifier_->isVisible()) {
clipboard::push(magnifier_->color(), magnifier_->colorname());
exit();
Expand Down
38 changes: 28 additions & 10 deletions src/widgets/framelesswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,41 @@ void FramelessWindow::toggleTransparentInput()

void FramelessWindow::mousePressEvent(QMouseEvent *event)
{
if (!isFullScreen() && event->button() == Qt::LeftButton) {
if (dragmove_ && !isFullScreen() && event->button() == Qt::LeftButton) {
dragmove_status_ = 1;
return;
}

QWidget::mousePressEvent(event);
}

void FramelessWindow::mouseMoveEvent(QMouseEvent *event)
{
if (dragmove_status_ == 1) {
dragmove_status_ = 2;
windowHandle()->startSystemMove();
return;
}

return QWidget::mousePressEvent(event);
QWidget::mouseMoveEvent(event);
}

void FramelessWindow::mouseReleaseEvent(QMouseEvent *event)
{
dragmove_status_ = 0;
QWidget::mouseReleaseEvent(event);
}

void FramelessWindow::closeEvent(QCloseEvent *event)
{
emit closed();
return QWidget::closeEvent(event);
QWidget::closeEvent(event);
}

void FramelessWindow::hideEvent(QHideEvent *event)
{
emit hidden();
return QWidget::hideEvent(event);
QWidget::hideEvent(event);
}

void FramelessWindow::changeEvent(QEvent *event)
Expand All @@ -109,7 +126,7 @@ void FramelessWindow::changeEvent(QEvent *event)
}

#ifdef Q_OS_LINUX
void FramelessWindow::updateCursor(Qt::Edges edges)
void FramelessWindow::updateCursor(const Qt::Edges edges)
{
switch (edges) {
case Qt::LeftEdge:
Expand All @@ -130,7 +147,7 @@ bool FramelessWindow::event(QEvent *event)
switch (event->type()) {
case QEvent::MouseButtonPress:
if (edges_) {
window()->windowHandle()->startSystemResize(edges_);
windowHandle()->startSystemResize(edges_);
return true;
}
break;
Expand Down Expand Up @@ -186,7 +203,7 @@ static bool IsFullscreen(HWND hwnd)
return monitor && (monitor->rcMonitor == winrect);
}

int FramelessWindow::ResizeHandleHeight(HWND hWnd)
static int ResizeHandleHeight(HWND hWnd)
{
const auto dpi = probe::graphics::retrieve_dpi_for_window(reinterpret_cast<uint64_t>(hWnd));

Expand Down Expand Up @@ -274,6 +291,7 @@ bool FramelessWindow::nativeEvent(const QByteArray& eventType, void *message, Q_
case HTLEFT:
case HTBOTTOMLEFT:
case HTBOTTOM: *result = HTCLIENT; return true;
default: break;
}
}

Expand All @@ -285,9 +303,9 @@ bool FramelessWindow::nativeEvent(const QByteArray& eventType, void *message, Q_
RECT rect{};
if (!::GetWindowRect(hwnd, &rect)) return false;

const POINT pos{ GET_X_LPARAM(wmsg->lParam), GET_Y_LPARAM(wmsg->lParam) };
if (!IsMaximized(hwnd) && (pos.y < rect.top + ResizeHandleHeight(hwnd))) {
*result = isSizeFixed() ? HTCAPTION : HTTOP;
if (!IsMaximized(hwnd) && !IsFullscreen(hwnd) &&
(GET_Y_LPARAM(wmsg->lParam) < rect.top + ResizeHandleHeight(hwnd))) {
*result = isSizeFixed() ? HTCLIENT : HTTOP;
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/widgets/framelesswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,25 @@ public slots:

protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;

void closeEvent(QCloseEvent *) override;
void hideEvent(QHideEvent *event) override;
void changeEvent(QEvent *) override;

bool transparent_input_{};

bool dragmove_{ true };
int dragmove_status_{};

#ifdef Q_OS_LINUX
Qt::Edges edges_{};
void updateCursor(Qt::Edges edges);
bool event(QEvent *event) override;
#endif

#ifdef Q_OS_WIN
int ResizeHandleHeight(HWND hWnd);

bool nativeEvent(const QByteArray& eventType, void *message, Q_NATIVE_EVENT_RESULT *result) override;
#endif
};
Expand Down
29 changes: 24 additions & 5 deletions src/widgets/titlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <fmt/format.h>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QShortcut>
#include <QStyle>
Expand Down Expand Up @@ -106,11 +105,31 @@ TitleBar::TitleBar(FramelessWindow *parent)
connect(window_, &QWidget::windowTitleChanged, icon, &QCheckBox::setText);
}

void TitleBar::mousePressEvent(QMouseEvent *)
void TitleBar::mousePressEvent(QMouseEvent *event)
{
if (!window()->isFullScreen()) {
window()->windowHandle()->startSystemMove();
if (!window_->isFullScreen() && event->button() == Qt::LeftButton) {
dragmove_status_ = 1;
return;
}

QWidget::mousePressEvent(event);
}

void TitleBar::mouseMoveEvent(QMouseEvent *event)
{
if (dragmove_status_ == 1) {
dragmove_status_ = 2;
window_->windowHandle()->startSystemMove();
return;
}

QWidget::mouseMoveEvent(event);
}

void TitleBar::mouseReleaseEvent(QMouseEvent *event)
{
dragmove_status_ = 0;
QWidget::mouseReleaseEvent(event);
}

void TitleBar::mouseDoubleClickEvent(QMouseEvent *) { window()->toggleMaximized(); }
void TitleBar::mouseDoubleClickEvent(QMouseEvent *) { window_->toggleMaximized(); }
6 changes: 4 additions & 2 deletions src/widgets/titlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ class TitleBar : public QWidget
public:
explicit TitleBar(FramelessWindow *parent);

[[nodiscard]] FramelessWindow *window() const { return window_; }

void setHideOnFullScreen(bool value = true) { hide_on_fullscreen_ = value; }

protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;

void mouseDoubleClickEvent(QMouseEvent *event) override;

private:
FramelessWindow *window_{};
bool hide_on_fullscreen_{ true };
int dragmove_status_{};
};
#endif //! CAPTURER_TITLE_BAR_H

0 comments on commit 7067dfb

Please sign in to comment.