FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
#pragma once
#include <QComboBox>
#include <QJsonArray>
#include <QLabel>
#include <QLineEdit>
#include <QList>
#include <QPair>
#include <QPushButton>
#include <QScrollArea>
#include <QSplitter>
#include <QStackedWidget>
#include <QTextEdit>
#include <QWidget>
namespace fincept::screens {
/// Support — two-panel layout: ticket sidebar + detail/create content area.
///
/// Internationalised: static chrome (top bar, sidebar header, filter combo,
/// stat captions) flows through tr() with member pointers re-set in
/// retranslateUi(). The content pages (empty / create / detail) are
/// rebuilt from build_*() on QEvent::LanguageChange, and load_tickets()
/// re-runs to refresh sidebar rows. In-progress form input is preserved
/// across language switches by snapshotting + restoring text fields.
class SupportScreen : public QWidget {
Q_OBJECT
public:
explicit SupportScreen(QWidget* parent = nullptr);
protected:
void changeEvent(QEvent* event) override;
/// Refresh the ticket list when the panel is shown again after a while —
/// replies from the support team otherwise only appeared on a manual ↻.
void showEvent(QShowEvent* event) override;
private:
// ── Layout ────────────────────────────────────────────────────────────────
QSplitter* splitter_ = nullptr;
QStackedWidget* content_stack_ = nullptr; // 0=empty, 1=create, 2=detail
// ── Top bar ───────────────────────────────────────────────────────────────
QLabel* title_lbl_ = nullptr;
QLabel* breadcrumb_lbl_ = nullptr;
// ── Sidebar ───────────────────────────────────────────────────────────────
QPushButton* new_ticket_btn_ = nullptr;
QLineEdit* search_input_ = nullptr;
QComboBox* filter_combo_ = nullptr;
QWidget* ticket_container_ = nullptr;
QScrollArea* list_scroll_ = nullptr;
QLabel* stat_total_ = nullptr;
QLabel* stat_open_ = nullptr;
QLabel* stat_resolved_ = nullptr;
// Stat captions ("Total" / "Open" / "Done") — separate from the counts.
QLabel* stat_total_caption_ = nullptr;
QLabel* stat_open_caption_ = nullptr;
QLabel* stat_resolved_caption_ = nullptr;
// ── Status bar ────────────────────────────────────────────────────────────
QLabel* status_dot_ = nullptr;
QLabel* status_lbl_ = nullptr;
QPushButton* refresh_btn_ = nullptr;
// ── Create view ───────────────────────────────────────────────────────────
QLineEdit* subject_input_ = nullptr;
QComboBox* category_combo_ = nullptr;
QComboBox* priority_combo_ = nullptr;
QTextEdit* desc_input_ = nullptr;
QPushButton* create_btn_ = nullptr;
QLabel* char_count_lbl_ = nullptr;
// ── Detail view ───────────────────────────────────────────────────────────
QLabel* detail_id_lbl_ = nullptr;
QLabel* detail_subject_lbl_ = nullptr;
QLabel* detail_status_lbl_ = nullptr;
QLabel* detail_meta_lbl_ = nullptr;
QLabel* detail_body_lbl_ = nullptr;
QWidget* messages_container_ = nullptr;
QScrollArea* detail_scroll_ = nullptr;
QTextEdit* msg_input_ = nullptr;
QPushButton* send_btn_ = nullptr;
QPushButton* close_btn_ = nullptr;
QPushButton* reopen_btn_ = nullptr;
QWidget* reply_box_ = nullptr;
QWidget* closed_box_ = nullptr;
// ── State ─────────────────────────────────────────────────────────────────
int selected_ticket_id_ = -1;
bool selected_is_closed_ = false;
QPushButton* active_row_btn_ = nullptr; // currently highlighted sidebar row
/// Last successfully-fetched ticket set. Cached so the search box and status
/// filter can re-render the sidebar without a network round-trip, and kept
/// (last-known-good) when a refresh fails.
QJsonArray all_tickets_;
bool load_failed_ = false;
/// Wall-clock ms of the last load_tickets() call; showEvent() only refetches
/// when the data is older than a minute.
qint64 last_load_ms_ = 0;
/// Categories the support API returned as (display text, API key) pairs.
/// Kept so a language switch — which rebuilds the create page with its
/// default category list — can restore the server-provided set.
QList<QPair<QString, QString>> server_categories_;
/// Fill category_combo_ from server_categories_ (no-op until the API answered).
void populate_category_combo();
// ── Builders ─────────────────────────────────────────────────────────────
QWidget* build_sidebar();
QWidget* build_empty_state();
QWidget* build_create_page();
QWidget* build_detail_page();
// ── Helpers ───────────────────────────────────────────────────────────────
void set_busy(bool busy);
void select_ticket_row(QPushButton* btn);
void apply_styles();
void retranslateUi();
static QString status_color(const QString& s);
static QString priority_color(const QString& p);
static QString status_label(const QString& s);
/// Re-render the sidebar rows from all_tickets_, honouring the search box
/// and the status filter combo. Called by load_tickets() and whenever
/// either control changes — no refetch.
void rebuild_ticket_rows();
/// Show a ticket from the cached list in the detail pane, then fetch its
/// full record (description + conversation) from the API.
void open_ticket(const QJsonObject& ticket);
void load_ticket_details(int ticket_id);
/// Header / meta / reply-box state for `status` ("open", "resolved", …).
void apply_detail_status(const QString& status);
// ── Slots ─────────────────────────────────────────────────────────────────
void load_tickets();
void on_create_ticket();
void on_send_message();
void on_close_ticket();
void on_reopen_ticket();
};
} // namespace fincept::screens