Skip to content

Commit

Permalink
Alt-Drag copy
Browse files Browse the repository at this point in the history
  • Loading branch information
khrykin committed Apr 16, 2020
1 parent efafef9 commit 60ca160
Show file tree
Hide file tree
Showing 28 changed files with 498 additions and 172 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ set(MODELS ${MODELS_PLATFORM_FILES}
models/selection.cpp
models/selection.h
models/event.cpp
models/event.h models/color.cpp models/color.h)
models/event.h
models/color.cpp
models/color.h)

set(MODELS_TESTS
models/tests/activity_tests.cpp
Expand Down Expand Up @@ -211,7 +213,7 @@ qt5_add_resources(RESOURCES
resources/fonts.qrc)

if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
set(MODELS_PLATFORM_LIBRARIES
"-framework Foundation"
"-framework AppKit"
Expand Down
6 changes: 4 additions & 2 deletions deployment/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>LSApplicationCategoryType</key>
Expand All @@ -20,8 +22,6 @@
<string>6.0</string>
<key>CFBundleName</key>
<string>Strategr</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>Bundle versions string, long</key>
Expand Down Expand Up @@ -53,5 +53,7 @@
<string>Strategr would be able to export activity sessions as events to the Calendar</string>
<key>SUFeedURL</key>
<string>${APPCAST_URL}</string>
<key>SUPublicEDKey</key>
<string>G0A4GIM5nGFE2ANNKzogtjCjWHwItD6oy56yL1qJngQ=</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion deployment/Strategr_x64.template.iss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OutputDir=..\builds\Windows\x64-Release\Installer
Source: "..\builds\Windows\x64-Release\Strategr\*"; DestDir: {app}; Flags: recursesubdirs;

[Run]
Filename: "{app}\vc_redist.x64.exe"; StatusMsg: "Installing Visual C++ Runtime..."; Parameters: "/passive /norestart; Check: VC2019RedistNeedsInstall; Flags: waituntilterminated
Filename: "{app}\vc_redist.x64.exe"; StatusMsg: "Installing Visual C++ Runtime..."; Parameters: "/passive /norestart"; Check: VC2019RedistNeedsInstall; Flags: waituntilterminated
Filename: "{app}\Strategr.exe"; Description: "Launch Strategr"; Flags: postinstall nowait

[Icons]
Expand Down
25 changes: 14 additions & 11 deletions models/activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
#include "activity.h"
#include "activityinvalidpropertyexception.h"

const std::vector<std::pair<stg::activity::color_t, std::string>>
stg::activity::default_colors = {
{"#FF6562", "Red"},
{"#FFB700", "Orange"},
{"#FFD600", "Yellow"},
{"#A463F2", "Purple"},
{"#D5008F", "Indigo"},
{"#19A974", "Green"},
{"#357EDD", "Blue"},
{"#000000", "Black"},
{"#777777", "Gray"}
const std::vector<stg::activity::color_info_t> &stg::activity::default_colors() {
const static std::vector<stg::activity::color_info_t> colors = {
{"#FF6562", "Red"},
{"#FFB700", "Orange"},
{"#FFD600", "Yellow"},
{"#A463F2", "Purple"},
{"#D5008F", "Indigo"},
{"#19A974", "Green"},
{"#357EDD", "Blue"},
{"#000000", "Black"},
{"#777777", "Gray"}
};

return colors;
};

stg::activity::activity(name_t name, color_t color) : _color(std::move(color)) {
Expand Down
4 changes: 3 additions & 1 deletion models/activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ namespace stg {
struct activity {
using color_t = stg::color;
using name_t = std::string;
using color_info_t = std::pair<color_t, std::string>;

class invalid_property_exception;

static constexpr auto default_color = "#000000";
static const std::vector<std::pair<color_t, std::string>> default_colors;
static const std::vector<color_info_t> &default_colors();

explicit activity(name_t name, color_t color = default_color) noexcept(false);

Expand Down
9 changes: 6 additions & 3 deletions models/dragoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ stg::drag_operation::drag_operation(time_slots_state *time_slots, indices_vector
initial_dragged_indices(std::move(initial_indices)) {
}

void stg::drag_operation::record_drag(const std::vector<time_slot> &time_slots_to_drag, int distance) {
std::vector<stg::drag_operation::index_t>
stg::drag_operation::record_drag(const std::vector<time_slot> &time_slots_to_drag, int distance) {
if (distance == 0) {
return;
return {};
}

auto range_to_drag = indices_range{*time_slots->index_of(time_slots_to_drag.front()),
*time_slots->index_of(time_slots_to_drag.back())};

// Drag operation_type is divided into two phases:
// 1. Drag selected slots to their new positions, switching them is nearby slots;
// 1. Drag selected slots to their new positions, switching the nearby slots;
auto new_dragged_indices = silently_drag(range_to_drag, distance);
// 2. Try to restore nearby sessions' initial positions.
invalidate_drag(new_dragged_indices);

return new_dragged_indices;
}

stg::drag_operation::indices_vector
Expand Down
4 changes: 2 additions & 2 deletions models/dragoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace stg {
explicit drag_operation(time_slots_state *time_slots,
indices_vector initial_indices);

void record_drag(const std::vector<time_slot> &time_slots_to_drag,
int distance);
std::vector<index_t> record_drag(const std::vector<time_slot> &time_slots_to_drag,
int distance);

bool state_changed();

Expand Down
7 changes: 6 additions & 1 deletion models/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace stg {
static constexpr key_modifiers right_key = 1u << 1u;
static constexpr key_modifiers ctrl_key = 1u << 2u;
static constexpr key_modifiers alt_key = 1u << 3u;
static constexpr key_modifiers shift_key = 1u << 4u;

explicit event(key_modifiers modifiers);

Expand All @@ -27,6 +28,10 @@ namespace stg {
if ((evt->modifiers() & 0x08000000) == 0x08000000) {
modifiers |= alt_key;
}

if ((evt->modifiers() & 0x02000000) == 0x02000000) {
modifiers |= shift_key;
}
}

bool has_only(key_modifiers mod) const;
Expand All @@ -36,7 +41,7 @@ namespace stg {
};

struct mouse_event : public event {
mouse_event(const point &position, key_modifiers modifiers = left_key);
explicit mouse_event(const point &position, key_modifiers modifiers = left_key);

template<class QtLikeEvent>
mouse_event(QtLikeEvent *evt) : event(evt), position(evt->pos()) {
Expand Down
8 changes: 4 additions & 4 deletions models/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ namespace stg {
}
};

constexpr inline point point::zero = point();
inline constexpr point point::zero = point();

struct rect {
static const rect zero;

int left = 0;
int top = 0;
int width = 0;
Expand Down Expand Up @@ -170,11 +172,9 @@ namespace stg {
<< r.height << " ]";
return os;
}

static const rect zero;
};

constexpr inline auto rect::zero = rect{0, 0, 0, 0};
inline constexpr rect rect::zero = rect{0, 0, 0, 0};
}

#endif //STRATEGR_GEOMETRY_H
40 changes: 32 additions & 8 deletions models/mousehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void stg::mouse_handler::mouse_press(const stg::mouse_event &event) {
current_key_modifiers = event.modifiers;

current_operaion = get_operation(current_key_modifiers);
current_operaion->init(event);
current_operaion->start(event);

if ((event.modifiers & event::right_key) == event::right_key && on_context_menu_event) {
on_context_menu_event(event.position,
Expand Down Expand Up @@ -62,7 +62,7 @@ void stg::mouse_handler::mouse_move(const stg::mouse_event &event) {
}

void stg::mouse_handler::mouse_release(const stg::mouse_event &event) {
current_operaion->teardown(event);
current_operaion->stop(event);
current_operaion = make_operation<none_operation>();

update_cursor(event.modifiers);
Expand All @@ -86,11 +86,33 @@ void stg::mouse_handler::mouse_release(const stg::mouse_event &event) {

void stg::mouse_handler::key_down(const event &event) {
current_key_modifiers |= event.modifiers;

if (current_operaion->type() == drag &&
current_operaion->state() == operation::state::started) {
if (event.with(event::alt_key)) {
auto fake_event = mouse_event(previous_position, event.modifiers);
current_operaion->stop(fake_event);
current_operaion = make_operation<copy_drag_operation>();
current_operaion->start(fake_event);
}
}

update_cursor(event.modifiers);
}

void stg::mouse_handler::key_up(const event &event) {
current_key_modifiers |= event.modifiers;

if (current_operaion->type() == copy_drag &&
current_operaion->state() == operation::state::started) {
if (!event.with(event::alt_key)) {
auto fake_event = mouse_event(previous_position, event.modifiers);
current_operaion->stop(fake_event);
current_operaion = make_operation<drag_operation>();
current_operaion->start(fake_event);
}
}

update_cursor(event.modifiers);
}

Expand All @@ -113,9 +135,6 @@ void stg::mouse_handler::handle_autoscroll(const stg::mouse_event &event) {
viewport.height
};

// std::cout << "viewport: " << viewport << " " << viewport.top + viewport.height << "\n";
// std::cout << "bounds: " << bounds << " " << bounds.top + bounds.height << "\n";

auto needs_autoscroll_top = top_autoscroll_zone.contains(pos_in_viewport.y) &&
viewport.top > -bounds.top &&
event.position.y > 0;
Expand All @@ -129,7 +148,7 @@ void stg::mouse_handler::handle_autoscroll(const stg::mouse_event &event) {
if (!autoscroll_is_on && needs_autoscroll) {
autoscroll_is_on = true;

scroll_direction direction = scroll_direction::down;
auto direction = scroll_direction::down;
if (needs_autoscroll_top) {
direction = scroll_direction::up;
} else if (needs_autoscroll_bottom) {
Expand Down Expand Up @@ -159,7 +178,8 @@ stg::mouse_handler::get_operation(event::key_modifiers modifiers) {

auto current_selected = selection.has_selected(current_slot_index);

if (modifiers == mouse_event::left_key) {
if (modifiers == mouse_event::left_key ||
modifiers == (mouse_event::left_key | mouse_event::shift_key)) {
if (!selection.empty() && current_selected) {
return make_operation<select_operation>();
}
Expand Down Expand Up @@ -315,7 +335,11 @@ stg::mouse_handler::get_cursor(event::key_modifiers modifiers) {
auto next_empty = time_slots.next_slot_empty(current_slot_index);
auto prev_empty = time_slots.previous_slot_empty(current_slot_index);

if ((modifiers & mouse_event::alt_key) == mouse_event::alt_key &&

auto alt_key_is_pressed = modifiers == (mouse_event::alt_key | mouse_event::left_key) ||
modifiers == mouse_event::alt_key;

if (alt_key_is_pressed &&
!current_slot.empty() &&
mouse_zone == mouse_zone::drag) {
return cursor::drag_copy;
Expand Down
Loading

0 comments on commit 60ca160

Please sign in to comment.