Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CameraView Overhaul #131

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ set(ELEMENTS
models/TabWidgetsModel
models/TabListModel
models/TopicListModel
models/CameraListModel
models/MapModel
models/AccentsListModel

Expand Down
54 changes: 11 additions & 43 deletions dialogs/TopicView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,32 @@ Row {

property alias menuAnim: menuAnim

property bool isCamera: false

property string closedText: isCamera ? "<<" : ">>"
property string openText: isCamera ? ">>" : "<<"
property string closedText: ">>"
property string openText: "<<"

width: (parent.width / 3) + 40
height: parent.height

SmoothedAnimation {
id: menuAnim
target: tv
property: "anchors." + (isCamera ? "right" : "left") + "Margin"
property: "anchors." + "left" + "Margin"
duration: 500
}

signal open
signal close

signal addWidget(string name, string topic, string type)
signal addCamera(string name, string source, var urls)
signal dragging(point pos)
signal dropped(point pos)

function widgetAdd(name, topic, type) {
button2.text = closedText
button.text = closedText
close()
addWidget(name, topic, type)
}

function cameraAdd(name, source, urls) {
button.text = (closedText)
close()
addCamera(name, source, urls)
}

Button {
id: button
text: closedText

width: isCamera ? 40 : 0
height: isCamera ? 40 : 0

onClicked: {
if (text === closedText) {
open()
text = openText
} else {
close()
text = closedText
}
}
}

Rectangle {
id: topicView
radius: 10
Expand All @@ -87,7 +60,7 @@ Row {

selectionModel: ItemSelectionModel {}

model: isCamera ? cameras : topics
model: topics

delegate: Item {
DragHandler {
Expand All @@ -105,13 +78,8 @@ Row {
let global = mapToItem(topicView, centroid.position)
if (!topicView.contains(global)) {
if (!ready) {
if (isCamera) {
cameraAdd(model.name, model.source,
model.urls)
} else {
widgetAdd(model.name, model.topic,
model.type)
}
widgetAdd(model.name, model.topic,
model.type)

ready = true
}
Expand Down Expand Up @@ -210,7 +178,7 @@ Row {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
clip: true
text: isCamera ? "" : model.type
text: model.type

color: Constants.palette.text

Expand All @@ -221,11 +189,11 @@ Row {
}

Button {
id: button2
id: button
text: closedText

width: !isCamera ? 40 : 0
height: !isCamera ? 40 : 0
width: 40
height: 40

onClicked: {
if (text === closedText) {
Expand Down
60 changes: 0 additions & 60 deletions include/models/CameraListModel.h

This file was deleted.

36 changes: 1 addition & 35 deletions items/MainScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,6 @@ Rectangle {
onDropped: pos => drop(pos, true)
}

TopicView {
id: cl

isCamera: true

onAddCamera: (name, source, urls) => {
currentTab().addCamera(name, source, urls)
}

anchors {
right: parent.right
rightMargin: -(parent.width / 3)

top: parent.top
bottom: parent.bottom
}

onOpen: {
menuAnim.from = -(parent.width / 3)
menuAnim.to = 0
menuAnim.start()
}

onClose: {
menuAnim.to = -(parent.width / 3)
menuAnim.from = 0
menuAnim.start()
}

onDragging: pos => drag(pos, true)

onDropped: pos => drop(pos, true)
}

TabNameDialog {
id: tabNameDialog
}
Expand Down Expand Up @@ -394,7 +360,7 @@ Rectangle {
anchors {
top: parent.top
left: tv.right
right: cl.left
right: parent.right

leftMargin: 0
rightMargin: 0
Expand Down
4 changes: 0 additions & 4 deletions items/Tab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ Rectangle {
twm.add(title, topic, type)
}

function addCamera(name, source, urls) {
twm.addCamera(name, source, urls)
}

function setName(name) {
model.title = name
}
Expand Down
19 changes: 1 addition & 18 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "AccentsListModel.h"
#include "BuildConfig.h"
#include "CameraListModel.h"
#include "Flags.h"
#include "Globals.h"
#include "TitleManager.h"
Expand All @@ -30,36 +29,21 @@ int main(int argc, char *argv[])

TabListModel *tlm = new TabListModel(settings, &app);

CameraListModel *clm = new CameraListModel(store, &app);

TitleManager *title = new TitleManager(&app);

AccentsListModel *accents = new AccentsListModel(&app);
accents->load();

Globals::inst.AddConnectionListener(true, [topics, &store, clm, title] (const nt::Event &event) {
Globals::inst.AddConnectionListener(true, [topics, &store, title] (const nt::Event &event) {
bool connected = event.Is(nt::EventFlags::kConnected);

store.connect(connected);

if (!connected) {
QMetaObject::invokeMethod(topics, &TopicListModel::clear);
QMetaObject::invokeMethod(clm, &CameraListModel::clear);
title->resetTitle();
} else {
title->setTitle("Connected (" + QString::fromStdString(event.GetConnectionInfo()->remote_ip) + ")");
QMetaObject::invokeMethod(clm, [=] {
// kind of hacky, but what works, works
QTimer::singleShot(1000, [=] {
clm->clear();

for (const std::string &st : Globals::inst.GetTable("/CameraPublisher")->GetSubTables()) {
std::shared_ptr<nt::NetworkTable> subtable = Globals::inst.GetTable("/CameraPublisher")->GetSubTable(st);

clm->add(subtable);
}
});
});
}
});

Expand Down Expand Up @@ -103,7 +87,6 @@ int main(int argc, char *argv[])

engine.rootContext()->setContextProperty("topics", topics);
engine.rootContext()->setContextProperty("settings", settings);
engine.rootContext()->setContextProperty("cameras", clm);
engine.rootContext()->setContextProperty("topicStore", &store);
engine.rootContext()->setContextProperty("tlm", tlm);
engine.rootContext()->setContextProperty("titleManager", title);
Expand Down
Loading
Loading