From 7efea428c75e78f16044171b2ed8a6e2b1bdd10c Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 19 Feb 2019 02:28:50 -0800 Subject: [PATCH] some refactoring work --- Doxyfile | 2 +- io/config.cpp | 12 ++-- io/config.h | 53 +++++++++-------- io/loadthread.cpp | 4 +- mainwindow.cpp | 14 ++--- panels/project.cpp | 24 ++++---- panels/timeline.cpp | 4 +- panels/viewer.cpp | 32 +++++----- panels/viewer.h | 2 +- playback/cacher.cpp | 4 +- playback/playback.cpp | 6 +- ui/graphview.cpp | 127 ++++++++++++++++++++-------------------- ui/graphview.h | 132 +++++++++++++++++++++--------------------- ui/timelinetools.h | 25 ++++---- 14 files changed, 223 insertions(+), 218 deletions(-) diff --git a/Doxyfile b/Doxyfile index bddbd4e1c..eab2bc788 100644 --- a/Doxyfile +++ b/Doxyfile @@ -457,7 +457,7 @@ LOOKUP_CACHE_SIZE = 0 # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = NO +EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. diff --git a/io/config.cpp b/io/config.cpp index d4cbac676..97f53aa92 100644 --- a/io/config.cpp +++ b/io/config.cpp @@ -43,7 +43,7 @@ Config::Config() img_seq_formats("jpg|jpeg|bmp|tiff|tif|psd|png|tga|jp2|gif"), rectified_waveforms(false), default_transition_length(30), - timecode_view(TIMECODE_DROP), + timecode_view(olive::kTimecodeDrop), show_title_safe_area(false), use_custom_title_safe_ratio(false), custom_title_safe_ratio(1), @@ -53,17 +53,17 @@ Config::Config() enable_seek_to_import(false), enable_audio_scrubbing(true), drop_on_media_to_replace(true), - autoscroll(AUTOSCROLL_PAGE_SCROLL), + autoscroll(olive::AUTOSCROLL_PAGE_SCROLL), audio_rate(48000), fast_seeking(false), hover_focus(false), - project_view_type(PROJECT_VIEW_TREE), + project_view_type(olive::PROJECT_VIEW_TREE), set_name_with_marker(true), show_project_toolbar(false), previous_queue_size(3), - previous_queue_type(FRAME_QUEUE_TYPE_FRAMES), + previous_queue_type(olive::FRAME_QUEUE_TYPE_FRAMES), upcoming_queue_size(0.5), - upcoming_queue_type(FRAME_QUEUE_TYPE_SECONDS), + upcoming_queue_type(olive::FRAME_QUEUE_TYPE_SECONDS), loop(false), seek_also_selects(false), effect_textbox_lines(3), @@ -234,7 +234,7 @@ void Config::save(QString path) { stream.writeStartDocument(); // doc stream.writeStartElement("Configuration"); // configuration - stream.writeTextElement("Version", QString::number(SAVE_VERSION)); + stream.writeTextElement("Version", QString::number(olive::kSaveVersion)); stream.writeTextElement("SavedLayout", QString::number(saved_layout)); stream.writeTextElement("ShowTrackLines", QString::number(show_track_lines)); stream.writeTextElement("ScrollZooms", QString::number(scroll_zooms)); diff --git a/io/config.h b/io/config.h index ea9614e00..bf91f8bde 100644 --- a/io/config.h +++ b/io/config.h @@ -23,36 +23,39 @@ #include -#define SAVE_VERSION 190219 // YYMMDD -#define MIN_SAVE_VERSION 190219 // lowest compatible project version +namespace olive { + const int kSaveVersion = 190219; // YYMMDD + const int kMinimumSaveVersion = 190219; // lowest compatible project version -enum TimecodeType { - TIMECODE_DROP, - TIMECODE_NONDROP, - TIMECODE_FRAMES, - TIMECODE_MILLISECONDS -}; + enum TimecodeType { + kTimecodeDrop, + kTimecodeNonDrop, + kTimecodeFrames, + kTimecodeMilliseconds + }; -enum RecordingMode { - RECORD_MODE_MONO, - RECORD_MODE_STEREO -}; + enum RecordingMode { + RECORD_MODE_MONO, + RECORD_MODE_STEREO + }; -enum AutoScrollMode { - AUTOSCROLL_NO_SCROLL, - AUTOSCROLL_PAGE_SCROLL, - AUTOSCROLL_SMOOTH_SCROLL -}; + enum AutoScrollMode { + AUTOSCROLL_NO_SCROLL, + AUTOSCROLL_PAGE_SCROLL, + AUTOSCROLL_SMOOTH_SCROLL + }; -enum ProjectView { - PROJECT_VIEW_TREE, - PROJECT_VIEW_ICON -}; + enum ProjectView { + PROJECT_VIEW_TREE, + PROJECT_VIEW_ICON + }; + + enum FrameQueueType { + FRAME_QUEUE_TYPE_FRAMES, + FRAME_QUEUE_TYPE_SECONDS + }; +} -enum FrameQueueType { - FRAME_QUEUE_TYPE_FRAMES, - FRAME_QUEUE_TYPE_SECONDS -}; struct Config { Config(); diff --git a/io/loadthread.cpp b/io/loadthread.cpp index 42a970673..270bea571 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -169,14 +169,14 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { show_err = true; - int proj_version = SAVE_VERSION; + int proj_version = olive::kSaveVersion; while (!stream.atEnd() && !cancelled) { read_next_start_element(stream); if (stream.name() == root_search) { if (type == LOAD_TYPE_VERSION) { proj_version = stream.readElementText().toInt(); - if (proj_version < MIN_SAVE_VERSION || proj_version > SAVE_VERSION) { + if (proj_version < olive::kMinimumSaveVersion || proj_version > olive::kSaveVersion) { emit start_question( tr("Version Mismatch"), tr("This project was saved in a different version of Olive and may not be fully compatible with this version. Would you like to attempt loading it anyway?"), diff --git a/mainwindow.cpp b/mainwindow.cpp index 1ee7b1b72..9b5fa3505 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -449,19 +449,19 @@ void MainWindow::setup_menus() { frames_action = view_menu->addAction(tr("Frames"), &olive::MenuHelper, SLOT(set_timecode_view())); frames_action->setProperty("id", "modeframes"); - frames_action->setData(TIMECODE_FRAMES); + frames_action->setData(olive::kTimecodeFrames); frames_action->setCheckable(true); drop_frame_action = view_menu->addAction(tr("Drop Frame"), &olive::MenuHelper, SLOT(set_timecode_view())); drop_frame_action->setProperty("id", "modedropframe"); - drop_frame_action->setData(TIMECODE_DROP); + drop_frame_action->setData(olive::kTimecodeDrop); drop_frame_action->setCheckable(true); nondrop_frame_action = view_menu->addAction(tr("Non-Drop Frame"), &olive::MenuHelper, SLOT(set_timecode_view())); nondrop_frame_action->setProperty("id", "modenondropframe"); - nondrop_frame_action->setData(TIMECODE_NONDROP); + nondrop_frame_action->setData(olive::kTimecodeNonDrop); nondrop_frame_action->setCheckable(true); milliseconds_action = view_menu->addAction(tr("Milliseconds"), &olive::MenuHelper, SLOT(set_timecode_view())); milliseconds_action->setProperty("id", "milliseconds"); - milliseconds_action->setData(TIMECODE_MILLISECONDS); + milliseconds_action->setData(olive::kTimecodeMilliseconds); milliseconds_action->setCheckable(true); view_menu->addSeparator(); @@ -700,17 +700,17 @@ void MainWindow::setup_menus() { no_autoscroll = tools_menu->addAction(tr("No Auto-Scroll"), &olive::MenuHelper, SLOT(set_autoscroll())); no_autoscroll->setProperty("id", "autoscrollno"); - no_autoscroll->setData(AUTOSCROLL_NO_SCROLL); + no_autoscroll->setData(olive::AUTOSCROLL_NO_SCROLL); no_autoscroll->setCheckable(true); page_autoscroll = tools_menu->addAction(tr("Page Auto-Scroll"), &olive::MenuHelper, SLOT(set_autoscroll())); page_autoscroll->setProperty("id", "autoscrollpage"); - page_autoscroll->setData(AUTOSCROLL_PAGE_SCROLL); + page_autoscroll->setData(olive::AUTOSCROLL_PAGE_SCROLL); page_autoscroll->setCheckable(true); smooth_autoscroll = tools_menu->addAction(tr("Smooth Auto-Scroll"), &olive::MenuHelper, SLOT(set_autoscroll())); smooth_autoscroll->setProperty("id", "autoscrollsmooth"); - smooth_autoscroll->setData(AUTOSCROLL_SMOOTH_SCROLL); + smooth_autoscroll->setData(olive::AUTOSCROLL_SMOOTH_SCROLL); smooth_autoscroll->setCheckable(true); tools_menu->addSeparator(); diff --git a/panels/project.cpp b/panels/project.cpp index ee316fb7f..ecc4efb37 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -432,10 +432,10 @@ void Project::new_folder() { QModelIndex index = olive::project_model.create_index(m->row(), 0, m); switch (olive::CurrentConfig.project_view_type) { - case PROJECT_VIEW_TREE: + case olive::PROJECT_VIEW_TREE: tree_view->edit(sorter->mapFromSource(index)); break; - case PROJECT_VIEW_ICON: + case olive::PROJECT_VIEW_ICON: icon_view->edit(sorter->mapFromSource(index)); break; } @@ -871,7 +871,7 @@ bool Project::reveal_media(Media *media, QModelIndex parent) { // retrieve its parent item QModelIndex hierarchy = sorted_index.parent(); - if (olive::CurrentConfig.project_view_type == PROJECT_VIEW_TREE) { + if (olive::CurrentConfig.project_view_type == olive::PROJECT_VIEW_TREE) { // if we're in tree view, expand every folder in the hierarchy containing the media while (hierarchy.isValid()) { @@ -886,7 +886,7 @@ bool Project::reveal_media(Media *media, QModelIndex parent) { ); tree_view->selectionModel()->select(row_select, QItemSelectionModel::Select); - } else if (olive::CurrentConfig.project_view_type == PROJECT_VIEW_ICON) { + } else if (olive::CurrentConfig.project_view_type == olive::PROJECT_VIEW_ICON) { // if we're in icon view, we just "browse" to the parent folder icon_view->setRootIndex(hierarchy); @@ -1206,7 +1206,7 @@ void Project::save_project(bool autorecovery) { stream.writeStartElement("project"); // project - stream.writeTextElement("version", QString::number(SAVE_VERSION)); + stream.writeTextElement("version", QString::number(olive::kSaveVersion)); stream.writeTextElement("url", olive::ActiveProjectFilename); proj_dir = QFileInfo(olive::ActiveProjectFilename).absoluteDir(); @@ -1240,26 +1240,26 @@ void Project::save_project(bool autorecovery) { } void Project::update_view_type() { - tree_view->setVisible(olive::CurrentConfig.project_view_type == PROJECT_VIEW_TREE); - icon_view_container->setVisible(olive::CurrentConfig.project_view_type == PROJECT_VIEW_ICON); + tree_view->setVisible(olive::CurrentConfig.project_view_type == olive::PROJECT_VIEW_TREE); + icon_view_container->setVisible(olive::CurrentConfig.project_view_type == olive::PROJECT_VIEW_ICON); switch (olive::CurrentConfig.project_view_type) { - case PROJECT_VIEW_TREE: + case olive::PROJECT_VIEW_TREE: sources_common->view = tree_view; break; - case PROJECT_VIEW_ICON: + case olive::PROJECT_VIEW_ICON: sources_common->view = icon_view; break; } } void Project::set_icon_view() { - olive::CurrentConfig.project_view_type = PROJECT_VIEW_ICON; + olive::CurrentConfig.project_view_type = olive::PROJECT_VIEW_ICON; update_view_type(); } void Project::set_tree_view() { - olive::CurrentConfig.project_view_type = PROJECT_VIEW_TREE; + olive::CurrentConfig.project_view_type = olive::PROJECT_VIEW_TREE; update_view_type(); } @@ -1343,7 +1343,7 @@ QVector Project::list_all_project_sequences() { } QModelIndexList Project::get_current_selected() { - if (olive::CurrentConfig.project_view_type == PROJECT_VIEW_TREE) { + if (olive::CurrentConfig.project_view_type == olive::PROJECT_VIEW_TREE) { return tree_view->selectionModel()->selectedRows(); } return icon_view->selectionModel()->selectedIndexes(); diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 227dd50b2..0b859c642 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -502,13 +502,13 @@ void Timeline::repaint_timeline() { && panel_sequence_viewer->playing && !zoom_just_changed) { // auto scroll - if (olive::CurrentConfig.autoscroll == AUTOSCROLL_PAGE_SCROLL) { + if (olive::CurrentConfig.autoscroll == olive::AUTOSCROLL_PAGE_SCROLL) { int playhead_x = getTimelineScreenPointFromFrame(olive::ActiveSequence->playhead); if (playhead_x < 0 || playhead_x > (editAreas->width() - videoScrollbar->width())) { horizontalScrollBar->setValue(getScreenPointFromFrame(zoom, olive::ActiveSequence->playhead)); draw = false; } - } else if (olive::CurrentConfig.autoscroll == AUTOSCROLL_SMOOTH_SCROLL) { + } else if (olive::CurrentConfig.autoscroll == olive::AUTOSCROLL_SMOOTH_SCROLL) { if (center_scroll_to_playhead(horizontalScrollBar, zoom, olive::ActiveSequence->playhead)) { draw = false; } diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 79d5321ef..06173285c 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -144,14 +144,14 @@ void Viewer::reset_all_audio() { long timecode_to_frame(const QString& s, int view, double frame_rate) { QList list = s.split(QRegExp("[:;]")); - if (view == TIMECODE_FRAMES || (list.size() == 1 && view != TIMECODE_MILLISECONDS)) { + if (view == olive::kTimecodeFrames || (list.size() == 1 && view != olive::kTimecodeMilliseconds)) { return s.toLong(); } int frRound = qRound(frame_rate); int hours, minutes, seconds, frames; - if (view == TIMECODE_MILLISECONDS) { + if (view == olive::kTimecodeMilliseconds) { long milliseconds = s.toLong(); hours = milliseconds/3600000; @@ -174,14 +174,14 @@ long timecode_to_frame(const QString& s, int view, double frame_rate) { int f = (frames + seconds + minutes + hours); - if ((view == TIMECODE_DROP || view == TIMECODE_MILLISECONDS) && frame_rate_is_droppable(frame_rate)) { + if ((view == olive::kTimecodeDrop || view == olive::kTimecodeMilliseconds) && frame_rate_is_droppable(frame_rate)) { // return drop int d; int m; - int dropFrames = round(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate - int framesPer10Minutes = round(frame_rate * 60 * 10); //Number of frames per ten minutes - int framesPerMinute = (round(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames + int dropFrames = qRound(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate + int framesPer10Minutes = qRound(frame_rate * 60 * 10); //Number of frames per ten minutes + int framesPerMinute = (qRound(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames d = f / framesPer10Minutes; f -= dropFrames*9*d; @@ -198,7 +198,7 @@ long timecode_to_frame(const QString& s, int view, double frame_rate) { } QString frame_to_timecode(long f, int view, double frame_rate) { - if (view == TIMECODE_FRAMES) { + if (view == olive::kTimecodeFrames) { return QString::number(f); } @@ -209,7 +209,7 @@ QString frame_to_timecode(long f, int view, double frame_rate) { int frames = 0; QString token = ":"; - if ((view == TIMECODE_DROP || view == TIMECODE_MILLISECONDS) && frame_rate_is_droppable(frame_rate)) { + if ((view == olive::kTimecodeDrop || view == olive::kTimecodeMilliseconds) && frame_rate_is_droppable(frame_rate)) { //CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE //Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team //Given an int called framenumber and a double called framerate @@ -218,11 +218,11 @@ QString frame_to_timecode(long f, int view, double frame_rate) { int d; int m; - int dropFrames = round(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate - int framesPerHour = round(frame_rate*60*60); //Number of frqRound64ames in an hour + int dropFrames = qRound(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate + int framesPerHour = qRound(frame_rate*60*60); //Number of frqRound64ames in an hour int framesPer24Hours = framesPerHour*24; //Number of frames in a day - timecode rolls over after 24 hours - int framesPer10Minutes = round(frame_rate * 60 * 10); //Number of frames per ten minutes - int framesPerMinute = (round(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames + int framesPer10Minutes = qRound(frame_rate * 60 * 10); //Number of frames per ten minutes + int framesPerMinute = (qRound(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames //If framenumber is greater than 24 hrs, next operation will rollover clock f = f % framesPer24Hours; //% is the modulus operator, which returns a remainder. a % b = the remainder of a/b @@ -237,7 +237,7 @@ QString frame_to_timecode(long f, int view, double frame_rate) { f = f + dropFrames*9*d; } - int frRound = round(frame_rate); + int frRound = qRound(frame_rate); frames = f % frRound; secs = (f / frRound) % 60; mins = ((f / frRound) / 60) % 60; @@ -253,7 +253,7 @@ QString frame_to_timecode(long f, int view, double frame_rate) { secs = f/int_fps % 60; frames = f%int_fps; } - if (view == TIMECODE_MILLISECONDS) { + if (view == olive::kTimecodeMilliseconds) { return QString::number((hours*3600000)+(mins*60000)+(secs*1000)+qCeil(frames*1000/frame_rate)); } return QString(QString::number(hours).rightJustified(2, '0') + @@ -263,8 +263,8 @@ QString frame_to_timecode(long f, int view, double frame_rate) { ); } -bool frame_rate_is_droppable(float rate) { - return (qFuzzyCompare(rate, 23.976f) || qFuzzyCompare(rate, 29.97f) || qFuzzyCompare(rate, 59.94f)); +bool frame_rate_is_droppable(double rate) { + return (qFuzzyCompare(rate, 23.976) || qFuzzyCompare(rate, 29.97) || qFuzzyCompare(rate, 59.94)); } void Viewer::seek(long p) { diff --git a/panels/viewer.h b/panels/viewer.h index f27a2cb24..0333966a8 100644 --- a/panels/viewer.h +++ b/panels/viewer.h @@ -36,7 +36,7 @@ #include "ui/labelslider.h" #include "ui/resizablescrollbar.h" -bool frame_rate_is_droppable(float rate); +bool frame_rate_is_droppable(double rate); long timecode_to_frame(const QString& s, int view, double frame_rate); QString frame_to_timecode(long f, int view, double frame_rate); diff --git a/playback/cacher.cpp b/playback/cacher.cpp index f974c8788..744080115 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -743,12 +743,12 @@ void open_clip_worker(ClipPtr clip) { clip->max_queue_size = 1; } else { clip->max_queue_size = 0; - if (olive::CurrentConfig.upcoming_queue_type == FRAME_QUEUE_TYPE_FRAMES) { + if (olive::CurrentConfig.upcoming_queue_type == olive::FRAME_QUEUE_TYPE_FRAMES) { clip->max_queue_size += qCeil(olive::CurrentConfig.upcoming_queue_size); } else { clip->max_queue_size += qCeil(ms->video_frame_rate * m->speed * olive::CurrentConfig.upcoming_queue_size); } - if (olive::CurrentConfig.previous_queue_type == FRAME_QUEUE_TYPE_FRAMES) { + if (olive::CurrentConfig.previous_queue_type == olive::FRAME_QUEUE_TYPE_FRAMES) { clip->max_queue_size += qCeil(olive::CurrentConfig.previous_queue_size); } else { clip->max_queue_size += qCeil(ms->video_frame_rate * m->speed * olive::CurrentConfig.previous_queue_size); diff --git a/playback/playback.cpp b/playback/playback.cpp index 000fb1735..55331e932 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -204,7 +204,7 @@ void get_clip_frame(ClipPtr c, long playhead, bool& texture_failed) { int64_t minimum_ts = target_frame->pts; int previous_frame_count = 0; - if (olive::CurrentConfig.previous_queue_type == FRAME_QUEUE_TYPE_SECONDS) { + if (olive::CurrentConfig.previous_queue_type == olive::FRAME_QUEUE_TYPE_SECONDS) { minimum_ts -= (second_pts*olive::CurrentConfig.previous_queue_size); } @@ -214,7 +214,7 @@ void get_clip_frame(ClipPtr c, long playhead, bool& texture_failed) { next_pts = c->queue.at(i)->pts; } if (c->queue.at(i) != target_frame && ((c->queue.at(i)->pts > minimum_ts) == c->reverse)) { - if (olive::CurrentConfig.previous_queue_type == FRAME_QUEUE_TYPE_SECONDS) { + if (olive::CurrentConfig.previous_queue_type == olive::FRAME_QUEUE_TYPE_SECONDS) { //dout << "removed frame at" << i << "because its pts was" << c->queue.at(i)->pts << "compared to" << target_frame->pts; av_frame_free(&c->queue[i]); // may be a little heavy for the main thread? c->queue.removeAt(i); @@ -226,7 +226,7 @@ void get_clip_frame(ClipPtr c, long playhead, bool& texture_failed) { } } - if (olive::CurrentConfig.previous_queue_type == FRAME_QUEUE_TYPE_FRAMES) { + if (olive::CurrentConfig.previous_queue_type == olive::FRAME_QUEUE_TYPE_FRAMES) { while (previous_frame_count > qCeil(olive::CurrentConfig.previous_queue_size)) { int smallest = 0; for (int i=1;iqueue.size();i++) { diff --git a/ui/graphview.cpp b/ui/graphview.cpp index bd87a8de3..4bcf35a9c 100644 --- a/ui/graphview.cpp +++ b/ui/graphview.cpp @@ -30,8 +30,6 @@ #include "panels/timeline.h" #include "panels/viewer.h" #include "project/sequence.h" -#include "project/effectrow.h" -#include "project/effectfield.h" #include "ui/keyframedrawing.h" #include "project/undo.h" #include "project/effect.h" @@ -40,14 +38,15 @@ #include "debug.h" -#define GRAPH_ZOOM_SPEED 0.05 -#define GRAPH_SIZE 100 -#define BEZIER_HANDLE_SIZE 3 -#define BEZIER_LINE_SIZE 2 -#define BEZIER_HANDLE_NONE 1 -#define BEZIER_HANDLE_PRE 2 -#define BEZIER_HANDLE_POST 3 +const double kGraphZoomSpeed = 0.05; +const int kGraphSize = 100; +const int kBezierHandleSize = 3; +const int kBezierLineSize = 2; + +const int kBezierHandleNone = 1; +const int kBezierHandlePre = 2; +const int kBezierHandlePost = 3; QColor get_curve_color(int index, int length) { QColor c; @@ -56,20 +55,20 @@ QColor get_curve_color(int index, int length) { return c; } -GraphView::GraphView(QWidget* parent) : - QWidget(parent), - x_scroll(0), - y_scroll(0), - mousedown(false), - x_zoom(1.0), - y_zoom(1.0), - row(nullptr), - moved_keys(false), - current_handle(BEZIER_HANDLE_NONE), - rect_select(false), - visible_in(0), - click_add_proc(false) +GraphView::GraphView(QWidget* parent) : QWidget(parent) { + x_scroll = 0; + y_scroll = 0; + mousedown = false; + x_zoom = 1.0; + y_zoom = 1.0; + row = nullptr; + moved_keys = false; + current_handle = kBezierHandleNone; + rect_select = false; + visible_in = 0; + click_add_proc = false; + setMouseTracking(true); setFocusPolicy(Qt::ClickFocus); setContextMenuPolicy(Qt::CustomContextMenu); @@ -176,7 +175,7 @@ void GraphView::set_view_to_rect(int x1, double y1, int x2, double y2) { void GraphView::draw_line_text(QPainter &p, bool vert, int line_no, int line_pos, int next_line_pos) { // draws last line's text - QString str = QString::number(line_no*GRAPH_SIZE); + QString str = QString::number(line_no*kGraphSize); int text_sz = vert ? fontMetrics().height() : fontMetrics().width(str); if (text_sz < (next_line_pos - line_pos)) { QRect text_rect = vert ? QRect(0, line_pos-50, 50, 50) : QRect(line_pos, height()-50, 50, 50); @@ -191,7 +190,7 @@ void GraphView::draw_lines(QPainter& p, bool vert) { int scroll = vert ? y_scroll : x_scroll; for (int i=0;ifieldCount()-1;i>=0;i--) { EffectField* field = row->field(i); @@ -321,12 +320,12 @@ void GraphView::paintEvent(QPaintEvent *) { // pre handle line QPointF pre_point(key_x + key.pre_handle_x*x_zoom, key_y - key.pre_handle_y*y_zoom); p.drawLine(pre_point, QPointF(key_x, key_y)); - p.drawEllipse(pre_point, BEZIER_HANDLE_SIZE, BEZIER_HANDLE_SIZE); + p.drawEllipse(pre_point, kBezierHandleSize, kBezierHandleSize); // post handle line QPointF post_point(key_x + key.post_handle_x*x_zoom, key_y - key.post_handle_y*y_zoom); p.drawLine(post_point, QPointF(key_x, key_y)); - p.drawEllipse(post_point, BEZIER_HANDLE_SIZE, BEZIER_HANDLE_SIZE); + p.drawEllipse(post_point, kBezierHandleSize, kBezierHandleSize); } bool selected = false; @@ -371,7 +370,7 @@ void GraphView::mousePressEvent(QMouseEvent *event) { // selecting int sel_key = -1; int sel_key_field = -1; - current_handle = BEZIER_HANDLE_NONE; + current_handle = kBezierHandleNone; if (click_add && (event->buttons() & Qt::LeftButton)) { selected_keys.clear(); @@ -404,19 +403,19 @@ void GraphView::mousePressEvent(QMouseEvent *event) { // selecting a handle QPointF pre_point(key_x + key.pre_handle_x*x_zoom, key_y - key.pre_handle_y*y_zoom); QPointF post_point(key_x + key.post_handle_x*x_zoom, key_y - key.post_handle_y*y_zoom); - if (event->pos().x() > pre_point.x()-BEZIER_HANDLE_SIZE - && event->pos().x() < pre_point.x()+BEZIER_HANDLE_SIZE - && event->pos().y() > pre_point.y()-BEZIER_HANDLE_SIZE - && event->pos().y() < pre_point.y()+BEZIER_HANDLE_SIZE) { - current_handle = BEZIER_HANDLE_PRE; - } else if (event->pos().x() > post_point.x()-BEZIER_HANDLE_SIZE - && event->pos().x() < post_point.x()+BEZIER_HANDLE_SIZE - && event->pos().y() > post_point.y()-BEZIER_HANDLE_SIZE - && event->pos().y() < post_point.y()+BEZIER_HANDLE_SIZE) { - current_handle = BEZIER_HANDLE_POST; + if (event->pos().x() > pre_point.x()-kBezierHandleSize + && event->pos().x() < pre_point.x()+kBezierHandleSize + && event->pos().y() > pre_point.y()-kBezierHandleSize + && event->pos().y() < pre_point.y()+kBezierHandleSize) { + current_handle = kBezierHandlePre; + } else if (event->pos().x() > post_point.x()-kBezierHandleSize + && event->pos().x() < post_point.x()+kBezierHandleSize + && event->pos().y() > post_point.y()-kBezierHandleSize + && event->pos().y() < post_point.y()+kBezierHandleSize) { + current_handle = kBezierHandlePost; } - if (current_handle != BEZIER_HANDLE_NONE) { + if (current_handle != kBezierHandleNone) { sel_key = j; sel_key_field = i; handle_index = j; @@ -437,7 +436,7 @@ void GraphView::mousePressEvent(QMouseEvent *event) { if (sel_key > -1) { for (int i=0;imodifiers() & Qt::ShiftModifier) && current_handle == BEZIER_HANDLE_NONE) { + if ((event->modifiers() & Qt::ShiftModifier) && current_handle == kBezierHandleNone) { selected_keys.removeAt(i); selected_keys_fields.removeAt(i); } @@ -513,7 +512,7 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { update(); } else { switch (current_handle) { - case BEZIER_HANDLE_NONE: + case kBezierHandleNone: for (int i=0;ifield(selected_keys_fields.at(i))->keyframes[selected_keys.at(i)].time = qRound(selected_keys_old_vals.at(i) + (double(event->pos().x() - start_x)/x_zoom)); if (event->modifiers() & Qt::ShiftModifier) { @@ -525,8 +524,8 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { moved_keys = true; update_ui(false); break; - case BEZIER_HANDLE_PRE: - case BEZIER_HANDLE_POST: + case kBezierHandlePre: + case kBezierHandlePost: { double new_pre_handle_x = old_pre_handle_x; double new_pre_handle_y = old_pre_handle_y; @@ -536,7 +535,7 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { double x_diff = double(event->pos().x() - start_x)/x_zoom; double y_diff = double(start_y - event->pos().y())/y_zoom; - if (current_handle == BEZIER_HANDLE_PRE) { + if (current_handle == kBezierHandlePre) { new_pre_handle_x += x_diff; if (!(event->modifiers() & Qt::ShiftModifier)) new_pre_handle_y += y_diff; if (!(event->modifiers() & Qt::ControlModifier)) { @@ -582,16 +581,16 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { KEYFRAME_SIZE+KEYFRAME_SIZE ); QRect pre_rect( - qRound(key_x + key.pre_handle_x*x_zoom - BEZIER_HANDLE_SIZE), - qRound(key_y + key.pre_handle_y*y_zoom - BEZIER_HANDLE_SIZE), - BEZIER_HANDLE_SIZE+BEZIER_HANDLE_SIZE, - BEZIER_HANDLE_SIZE+BEZIER_HANDLE_SIZE + qRound(key_x + key.pre_handle_x*x_zoom - kBezierHandleSize), + qRound(key_y + key.pre_handle_y*y_zoom - kBezierHandleSize), + kBezierHandleSize+kBezierHandleSize, + kBezierHandleSize+kBezierHandleSize ); QRect post_rect( - qRound(key_x + key.post_handle_x*x_zoom - BEZIER_HANDLE_SIZE), - qRound(key_y + key.post_handle_y*y_zoom - BEZIER_HANDLE_SIZE), - BEZIER_HANDLE_SIZE+BEZIER_HANDLE_SIZE, - BEZIER_HANDLE_SIZE+BEZIER_HANDLE_SIZE + qRound(key_x + key.post_handle_x*x_zoom - kBezierHandleSize), + qRound(key_y + key.post_handle_y*y_zoom - kBezierHandleSize), + kBezierHandleSize+kBezierHandleSize, + kBezierHandleSize+kBezierHandleSize ); if (test_rect.contains(event->pos()) @@ -611,16 +610,16 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { if (event->pos().x() <= get_screen_x(f->keyframes.at(sorted_keys.first()).time)) { int y_comp = get_screen_y(f->keyframes.at(sorted_keys.first()).data.toDouble()); - if (event->pos().y() >= y_comp-BEZIER_LINE_SIZE - && event->pos().y() <= y_comp+BEZIER_LINE_SIZE) { + if (event->pos().y() >= y_comp-kBezierLineSize + && event->pos().y() <= y_comp+kBezierLineSize) { // dout << "make an EARLY key on field" << i; click_add = true; click_add_type = f->keyframes.at(sorted_keys.first()).type; } } else if (event->pos().x() >= get_screen_x(f->keyframes.at(sorted_keys.last()).time)) { int y_comp = get_screen_y(f->keyframes.at(sorted_keys.last()).data.toDouble()); - if (event->pos().y() >= y_comp-BEZIER_LINE_SIZE - && event->pos().y() <= y_comp+BEZIER_LINE_SIZE) { + if (event->pos().y() >= y_comp-kBezierLineSize + && event->pos().y() <= y_comp+kBezierLineSize) { // dout << "make an LATE key on field" << i; click_add = true; click_add_type = f->keyframes.at(sorted_keys.last()).type; @@ -639,12 +638,12 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) { if (event->pos().x() >= last_key_x && event->pos().x() <= key_x) { - QRect mouse_rect(event->pos().x()-BEZIER_LINE_SIZE, event->pos().y()-BEZIER_LINE_SIZE, BEZIER_LINE_SIZE+BEZIER_LINE_SIZE, BEZIER_LINE_SIZE+BEZIER_LINE_SIZE); + QRect mouse_rect(event->pos().x()-kBezierLineSize, event->pos().y()-kBezierLineSize, kBezierLineSize+kBezierLineSize, kBezierLineSize+kBezierLineSize); // NOTE: FILTHY copy/paste from paintEvent if (last_key.type == EFFECT_KEYFRAME_HOLD) { // hold - if (event->pos().y() >= last_key_y-BEZIER_LINE_SIZE - && event->pos().y() <= last_key_y+BEZIER_LINE_SIZE) { + if (event->pos().y() >= last_key_y-kBezierLineSize + && event->pos().y() <= last_key_y+kBezierLineSize) { // dout << "make an HOLD key on field" << i << "after key" << j; click_add = true; } @@ -705,15 +704,15 @@ void GraphView::mouseReleaseEvent(QMouseEvent *) { } else if (moved_keys && selected_keys.size() > 0) { ComboAction* ca = new ComboAction(); switch (current_handle) { - case BEZIER_HANDLE_NONE: + case kBezierHandleNone: for (int i=0;ifield(selected_keys_fields.at(i))->keyframes[selected_keys.at(i)]; ca->append(new SetLong(&key.time, selected_keys_old_vals.at(i), key.time)); ca->append(new SetQVariant(&key.data, selected_keys_old_doubles.at(i), key.data)); } break; - case BEZIER_HANDLE_PRE: - case BEZIER_HANDLE_POST: + case kBezierHandlePre: + case kBezierHandlePost: { EffectKeyframe& key = row->field(handle_field)->keyframes[handle_index]; ca->append(new SetDouble(&key.pre_handle_x, old_pre_handle_x, key.pre_handle_x)); @@ -756,7 +755,7 @@ void GraphView::wheelEvent(QWheelEvent *event) { int x_delta = (event->modifiers() & Qt::ControlModifier) ? event->angleDelta().x() : y_delta; if (y_delta != 0) { - double zoom_diff = (GRAPH_ZOOM_SPEED*y_zoom); + double zoom_diff = (kGraphZoomSpeed*y_zoom); new_y_zoom = (y_delta < 0) ? y_zoom - zoom_diff : y_zoom + zoom_diff; // center zoom on screen @@ -766,7 +765,7 @@ void GraphView::wheelEvent(QWheelEvent *event) { } if (x_delta != 0) { - double zoom_diff = (GRAPH_ZOOM_SPEED*x_zoom); + double zoom_diff = (kGraphZoomSpeed*x_zoom); new_x_zoom = (x_delta < 0) ? x_zoom - zoom_diff : x_zoom + zoom_diff; set_scroll_x(qRound((double(x_scroll)/x_zoom*new_x_zoom) + double(event->pos().x())*new_x_zoom - double(event->pos().x())*x_zoom)); diff --git a/ui/graphview.h b/ui/graphview.h index 19247a2a1..203e80202 100644 --- a/ui/graphview.h +++ b/ui/graphview.h @@ -24,99 +24,99 @@ #include #include -class EffectRow; -class EffectField; +#include "project/effectrow.h" +#include "project/effectfield.h" QColor get_curve_color(int index, int length); class GraphView : public QWidget { - Q_OBJECT + Q_OBJECT public: - GraphView(QWidget* parent = 0); + GraphView(QWidget* parent = nullptr); - void paintEvent(QPaintEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); - void set_row(EffectRow* r); + void set_row(EffectRow* r); - void set_selected_keyframe_type(int type); - void set_field_visibility(int field, bool b); + void set_selected_keyframe_type(int type); + void set_field_visibility(int field, bool b); - void delete_selected_keys(); - void select_all(); + void delete_selected_keys(); + void select_all(); signals: - void x_scroll_changed(int); - void y_scroll_changed(int); - void zoom_changed(double, double); - void selection_changed(bool, int); + void x_scroll_changed(int); + void y_scroll_changed(int); + void zoom_changed(double, double); + void selection_changed(bool, int); private: - int x_scroll; - int y_scroll; - bool mousedown; - int start_x; - int start_y; + int x_scroll; + int y_scroll; + bool mousedown; + int start_x; + int start_y; - double x_zoom; - double y_zoom; + double x_zoom; + double y_zoom; - void set_scroll_x(int s); - void set_scroll_y(int s); - void set_zoom(double xz, double yz); + void set_scroll_x(int s); + void set_scroll_y(int s); + void set_zoom(double xz, double yz); - int get_screen_x(double); - int get_screen_y(double); - long get_value_x(int); - double get_value_y(int); + int get_screen_x(double); + int get_screen_y(double); + long get_value_x(int); + double get_value_y(int); - void selection_update(); + void selection_update(); - QVector field_visibility; + QVector field_visibility; - QVector selected_keys; - QVector selected_keys_fields; - QVector selected_keys_old_vals; - QVector selected_keys_old_doubles; + QVector selected_keys; + QVector selected_keys_fields; + QVector selected_keys_old_vals; + QVector selected_keys_old_doubles; - double old_pre_handle_x; - double old_pre_handle_y; - double old_post_handle_x; - double old_post_handle_y; + double old_pre_handle_x; + double old_pre_handle_y; + double old_post_handle_x; + double old_post_handle_y; - int handle_field; - int handle_index; + int handle_field; + int handle_index; - bool moved_keys; + bool moved_keys; - int current_handle; + int current_handle; - void draw_lines(QPainter &p, bool vert); - void draw_line_text(QPainter &p, bool vert, int line_no, int line_pos, int next_line_pos); + void draw_lines(QPainter &p, bool vert); + void draw_line_text(QPainter &p, bool vert, int line_no, int line_pos, int next_line_pos); - EffectRow* row; + EffectRow* row; - bool rect_select; - int rect_select_x; - int rect_select_y; - int rect_select_w; - int rect_select_h; - int rect_select_offset; + bool rect_select; + int rect_select_x; + int rect_select_y; + int rect_select_w; + int rect_select_h; + int rect_select_offset; - long visible_in; + long visible_in; - bool click_add; - bool click_add_proc; - EffectField* click_add_field; - int click_add_key; - int click_add_type; + bool click_add; + bool click_add_proc; + EffectField* click_add_field; + int click_add_key; + int click_add_type; private slots: - void show_context_menu(const QPoint& pos); - void reset_view(); - void set_view_to_selection(); - void set_view_to_all(); - void set_view_to_rect(int x1, double y1, int x2, double y2); + void show_context_menu(const QPoint& pos); + void reset_view(); + void set_view_to_selection(); + void set_view_to_all(); + void set_view_to_rect(int x1, double y1, int x2, double y2); }; #endif // GRAPHVIEW_H diff --git a/ui/timelinetools.h b/ui/timelinetools.h index bcc10bab6..de54fa8a2 100644 --- a/ui/timelinetools.h +++ b/ui/timelinetools.h @@ -21,16 +21,19 @@ #ifndef TIMELINETOOLS_H #define TIMELINETOOLS_H -#define TIMELINE_TOOL_POINTER 0 -#define TIMELINE_TOOL_EDIT 1 -#define TIMELINE_TOOL_RAZOR 2 -#define TIMELINE_TOOL_RIPPLE 3 -#define TIMELINE_TOOL_ROLLING 4 -#define TIMELINE_TOOL_SLIP 5 -#define TIMELINE_TOOL_SLIDE 6 -#define TIMELINE_TOOL_HAND 7 -#define TIMELINE_TOOL_ZOOM 8 -#define TIMELINE_TOOL_MENU 9 -#define TIMELINE_TOOL_TRANSITION 10 +enum TimelineTool { + TIMELINE_TOOL_POINTER, + TIMELINE_TOOL_EDIT, + TIMELINE_TOOL_RAZOR, + TIMELINE_TOOL_RIPPLE, + TIMELINE_TOOL_ROLLING, + TIMELINE_TOOL_SLIP, + TIMELINE_TOOL_SLIDE, + TIMELINE_TOOL_HAND, + TIMELINE_TOOL_ZOOM, + TIMELINE_TOOL_MENU, + TIMELINE_TOOL_TRANSITION, + TIMELINE_TOOL_COUNT +}; #endif // TIMELINETOOLS_H