diff --git a/apps/desktop/CMakeLists.txt b/apps/desktop/CMakeLists.txt index 619df3b..650c45a 100644 --- a/apps/desktop/CMakeLists.txt +++ b/apps/desktop/CMakeLists.txt @@ -44,6 +44,38 @@ else() endif() endif() +# Screen view models and list models of the UI layer. Shared by the app and +# the test target. +set(DESKTOP_UI_VIEWMODEL_SOURCES + src/viewmodels/AdminViewModel.cpp + src/viewmodels/BackendStatusViewModel.cpp + src/viewmodels/ChatViewModel.cpp + src/viewmodels/DashboardViewModel.cpp + src/viewmodels/DemoData.cpp + src/viewmodels/FormValidator.cpp + src/viewmodels/InterviewListModel.cpp + src/viewmodels/MessageListModel.cpp + src/viewmodels/QuestionListModel.cpp + src/viewmodels/ReportViewModel.cpp + src/viewmodels/SettingsViewModel.cpp + src/viewmodels/SetupViewModel.cpp +) +set(DESKTOP_UI_VIEWMODEL_HEADERS + include/viewmodels/AdminViewModel.hpp + include/viewmodels/BackendStatusViewModel.hpp + include/viewmodels/ChatViewModel.hpp + include/viewmodels/DashboardViewModel.hpp + include/viewmodels/DemoData.hpp + include/viewmodels/FormValidator.hpp + include/viewmodels/InterviewListModel.hpp + include/viewmodels/MessageListModel.hpp + include/viewmodels/QuestionListModel.hpp + include/viewmodels/ReportViewModel.hpp + include/viewmodels/SettingsViewModel.hpp + include/viewmodels/SetupViewModel.hpp + include/viewmodels/ViewModelSupport.hpp +) + add_executable(DevDialogue src/main.cpp @@ -78,6 +110,8 @@ add_executable(DevDialogue include/viewmodels/AuthViewModel.hpp src/viewmodels/NavigationViewModel.cpp include/viewmodels/NavigationViewModel.hpp + ${DESKTOP_UI_VIEWMODEL_SOURCES} + ${DESKTOP_UI_VIEWMODEL_HEADERS} ) target_include_directories(DevDialogue PRIVATE @@ -108,14 +142,86 @@ if(WIN32) target_link_libraries(DevDialogue PRIVATE Crypt32 Advapi32) endif() +# Application icon shown by Explorer and the taskbar (resources/app). +if(WIN32) + target_sources(DevDialogue PRIVATE resources/app/app-icon.rc) +endif() + +# Design-token singletons (each file also declares `pragma Singleton`). +set_source_files_properties( + qml/styles/Theme.qml + qml/styles/Typography.qml + qml/styles/Icons.qml + qml/styles/I18n.qml + PROPERTIES QT_QML_SINGLETON_TYPE TRUE +) + +# Bundled icon set (see resources/NOTICE.md). +file(GLOB DESKTOP_ICON_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_DEPENDS + resources/icons/*.svg +) + qt_add_qml_module(DevDialogue URI "DevDialogue.App" VERSION 1.0 QML_FILES qml/Main.qml + + # Design tokens qml/styles/Theme.qml - qml/components/Navbar.qml - qml/views/LandingView.qml + qml/styles/Typography.qml + qml/styles/Icons.qml + qml/styles/I18n.qml + + # Reusable components + qml/components/AlertBox.qml + qml/components/AppPage.qml + qml/components/AppText.qml + qml/components/AppToolTip.qml + qml/components/Badge.qml + qml/components/DarkCard.qml + qml/components/DarkTextArea.qml + qml/components/DarkTextField.qml + qml/components/GlowBlob.qml + qml/components/Icon.qml + qml/components/KpiTile.qml + qml/components/MessageBubble.qml + qml/components/ModalOverlay.qml + qml/components/MonoText.qml + qml/components/ProgressRing.qml + qml/components/PulseDot.qml + qml/components/ScoreGauge.qml + qml/components/SegmentedControl.qml + qml/components/SelectBox.qml + qml/components/SelectCard.qml + qml/components/Sidebar.qml + qml/components/SidebarItem.qml + qml/components/Skeleton.qml + qml/components/SoftGlow.qml + qml/components/Spinner.qml + qml/components/SplashOverlay.qml + qml/components/TactileButton.qml + qml/components/ThemedScrollBar.qml + qml/components/Toast.qml + qml/components/ToggleSwitch.qml + qml/components/UserAvatar.qml + + # Screens + qml/views/LoginView.qml + qml/views/DashboardView.qml + qml/views/SetupView.qml + qml/views/ChatRoomView.qml + qml/views/ReportView.qml + qml/views/AdminView.qml + qml/views/AccountView.qml + RESOURCES + resources/fonts/Geist-Variable.ttf + resources/fonts/GeistMono-Variable.ttf + resources/app/app-icon.svg + resources/app/app-icon.png + ${DESKTOP_ICON_FILES} ) # ========================================== @@ -132,6 +238,9 @@ if(GTest_FOUND) tests/unit/TestSecureStorage.cpp tests/unit/TestApiClient.cpp tests/unit/TestAuthService.cpp + tests/unit/TestFormValidator.cpp + tests/unit/TestListModels.cpp + tests/unit/TestViewModels.cpp # Headers for AUTOMOC include/core/AppConfig.hpp @@ -145,6 +254,8 @@ if(GTest_FOUND) include/services/AuthService.hpp include/services/InterviewService.hpp include/services/AdminService.hpp + include/viewmodels/NavigationViewModel.hpp + ${DESKTOP_UI_VIEWMODEL_HEADERS} # Sources required for tests src/core/AppConfig.cpp @@ -154,6 +265,8 @@ if(GTest_FOUND) src/services/AuthService.cpp src/services/InterviewService.cpp src/services/AdminService.cpp + src/viewmodels/NavigationViewModel.cpp + ${DESKTOP_UI_VIEWMODEL_SOURCES} ) target_include_directories(DevDialogueTests PRIVATE diff --git a/apps/desktop/include/viewmodels/AdminViewModel.hpp b/apps/desktop/include/viewmodels/AdminViewModel.hpp new file mode 100644 index 0000000..6da6eeb --- /dev/null +++ b/apps/desktop/include/viewmodels/AdminViewModel.hpp @@ -0,0 +1,130 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "services/AdminService.hpp" +#include "services/AuthService.hpp" +#include "viewmodels/QuestionListModel.hpp" +#include "viewmodels/ViewModelSupport.hpp" + +namespace devdialogue::viewmodels { + +// Question bank administration (port of the data side of the web +// AdminPanel.tsx): filtered and paged question list, create, delete and the +// active / inactive switch. +class AdminViewModel : public QObject, public support::BackendAware { + Q_OBJECT + Q_PROPERTY(QAbstractItemModel* questions READ questions CONSTANT) + Q_PROPERTY(int questionCount READ questionCount NOTIFY questionsChanged) + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) + Q_PROPERTY(bool isSubmitting READ isSubmitting NOTIFY submittingChanged) + Q_PROPERTY(bool isDemoData READ isDemoData NOTIFY questionsChanged) + // "" (all tracks) or a track id such as "frontend". + Q_PROPERTY(QString directionFilter READ directionFilter WRITE setDirectionFilter NOTIFY directionFilterChanged) + Q_PROPERTY(int page READ page NOTIFY pageChanged) + Q_PROPERTY(int totalPages READ totalPages NOTIFY pageChanged) + Q_PROPERTY(int totalCount READ totalCount NOTIFY pageChanged) + Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) + // Language of the sample questions shown when the backend is unreachable. + Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUiLanguage NOTIFY uiLanguageChanged) + +public: + explicit AdminViewModel(std::shared_ptr adminService, + std::shared_ptr authService, QObject* parent = nullptr); + ~AdminViewModel() override; + + QAbstractItemModel* questions() { return &m_questions; } + int questionCount() const { return m_questions.count(); } + bool loading() const { return m_loading; } + bool isSubmitting() const { return m_isSubmitting; } + bool isDemoData() const { return m_isDemoData; } + QString directionFilter() const { return m_directionFilter; } + void setDirectionFilter(const QString& direction); + int page() const { return m_page; } + int totalPages() const { return m_totalPages; } + int totalCount() const { return m_totalCount; } + QString errorMessage() const { return m_errorMessage; } + QString uiLanguage() const { return m_uiLanguage; } + void setUiLanguage(const QString& language); + + Q_INVOKABLE void refresh(); + Q_INVOKABLE void nextPage(); + Q_INVOKABLE void previousPage(); + + // Adds a question; emits questionCreated() when it is in the list. + Q_INVOKABLE void createQuestion(const QString& direction, const QString& level, const QString& topic, + const QString& questionText); + // Takes the question out of the list at once and emits questionDeleted(); + // the server is told only when the undo window has passed. + Q_INVOKABLE void deleteQuestion(const QString& id); + // Puts the question that is waiting to be deleted back in its row. + Q_INVOKABLE void undoDelete(); + // Sends the delete still waiting out its undo window now, e.g. when the + // window closes. Returns true while deletes are on their way to the + // server; deletesSettled() follows once they are all answered. + Q_INVOKABLE bool sendPendingDeletes(); + + // How long a deleted question can be restored (tests shorten it). + void setUndoWindow(int milliseconds) { m_undoTimer.setInterval(milliseconds); } + Q_INVOKABLE void setQuestionActive(const QString& id, bool active); + +signals: + void questionsChanged(); + void loadingChanged(); + void submittingChanged(); + void directionFilterChanged(); + void pageChanged(); + void errorMessageChanged(); + void uiLanguageChanged(); + void questionCreated(); + void questionDeleted(const QString& topic); + // The server kept the question, so it is back in the list. reason is the + // server's message, empty when the server could not be reached. + void questionDeleteFailed(const QString& topic, const QString& reason); + // Every delete sent to the server has been answered. + void deletesSettled(); + +private: + struct PendingDelete { + int row; + models::QuestionBankItem item; + }; + + // Sends the delete that is waiting out its undo window, if any. + void commitPendingDelete(); + void applyDemoQuestions(); + void setLoading(bool value); + void setSubmitting(bool submitting); + void setErrorMessage(const QString& message); + void setPaging(int page, int totalPages, int totalCount); + // Keeps "N questions" in step with rows added or removed here. + void adjustTotalCount(int delta); + + std::shared_ptr m_adminService; + std::shared_ptr m_authService; + QuestionListModel m_questions; + QTimer m_undoTimer; + std::optional m_pendingDelete; + // Deletes sent to the server and not answered yet; a page loaded + // meanwhile must not bring them back. + QSet m_deletingIds; + QString m_directionFilter; + QString m_errorMessage; + QString m_uiLanguage{QStringLiteral("en")}; + int m_page{1}; + int m_totalPages{1}; + int m_totalCount{0}; + int m_generation{0}; + bool m_loading{false}; + bool m_isSubmitting{false}; + bool m_isDemoData{false}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/BackendStatusViewModel.hpp b/apps/desktop/include/viewmodels/BackendStatusViewModel.hpp new file mode 100644 index 0000000..464f638 --- /dev/null +++ b/apps/desktop/include/viewmodels/BackendStatusViewModel.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "network/ApiClient.hpp" + +namespace devdialogue::viewmodels { + +// Backend connectivity state for the sidebar indicator and the account +// page. The online flag itself is owned by ApiClient; this class adds the +// on-demand check and its "checking" state. +class BackendStatusViewModel : public QObject { + Q_OBJECT + Q_PROPERTY(bool isOffline READ isOffline NOTIFY statusChanged) + Q_PROPERTY(bool isChecking READ isChecking NOTIFY checkingChanged) + +public: + explicit BackendStatusViewModel(std::shared_ptr apiClient, QObject* parent = nullptr); + + bool isOffline() const; + bool isChecking() const { return m_isChecking; } + + Q_INVOKABLE void checkHealth(); + +signals: + void statusChanged(); + void checkingChanged(); + +private: + void setChecking(bool checking); + + std::shared_ptr m_apiClient; + bool m_isChecking{false}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/ChatViewModel.hpp b/apps/desktop/include/viewmodels/ChatViewModel.hpp new file mode 100644 index 0000000..4e3ecd9 --- /dev/null +++ b/apps/desktop/include/viewmodels/ChatViewModel.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "services/InterviewService.hpp" +#include "viewmodels/MessageListModel.hpp" +#include "viewmodels/NavigationViewModel.hpp" +#include "viewmodels/ViewModelSupport.hpp" + +namespace devdialogue::viewmodels { + +// Interview room controller (port of the web ChatRoom.tsx): the transcript, +// sending answers, the session clock and finishing the interview. +class ChatViewModel : public QObject, public support::BackendAware { + Q_OBJECT + Q_PROPERTY(QString interviewId READ interviewId NOTIFY sessionChanged) + Q_PROPERTY(QString currentDirection READ currentDirection NOTIFY sessionChanged) + Q_PROPERTY(QString currentLevel READ currentLevel NOTIFY sessionChanged) + Q_PROPERTY(QString sessionLanguage READ sessionLanguage NOTIFY sessionChanged) + Q_PROPERTY(QAbstractItemModel* messagesModel READ messagesModel CONSTANT) + Q_PROPERTY(int candidateAnswersCount READ candidateAnswersCount NOTIFY messagesChanged) + Q_PROPERTY(bool isBusy READ isBusy NOTIFY busyChanged) + Q_PROPERTY(bool isCompleting READ isCompleting NOTIFY completingChanged) + Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) + Q_PROPERTY(QString elapsedText READ elapsedText NOTIFY elapsedChanged) + // True for a session that runs locally without the backend. + Q_PROPERTY(bool isLocalSession READ isLocalSession NOTIFY sessionChanged) + // A session is open and not finished yet (drives the sidebar entry). + Q_PROPERTY(bool hasActiveSession READ hasActiveSession NOTIFY sessionChanged) + +public: + explicit ChatViewModel(std::shared_ptr interviewService, + NavigationViewModel* navigation, QObject* parent = nullptr); + + QString interviewId() const { return m_interviewId; } + QString currentDirection() const { return m_direction; } + QString currentLevel() const { return m_level; } + QString sessionLanguage() const { return m_language; } + QAbstractItemModel* messagesModel() { return &m_messages; } + int candidateAnswersCount() const { return m_messages.userMessageCount(); } + bool isBusy() const { return m_isBusy; } + bool isCompleting() const { return m_isCompleting; } + QString errorMessage() const { return m_errorMessage; } + // Session time as "mm:ss". + QString elapsedText() const; + bool isLocalSession() const { return m_offline; } + bool hasActiveSession() const { return !m_interviewId.isEmpty() && !m_completed; } + + // Posts the candidate's answer and appends the interviewer's reply. If + // the backend is unreachable a scripted demo reply is used instead. + Q_INVOKABLE void sendAnswer(const QString& text); + + // Finishes the interview and opens the report. + Q_INVOKABLE void completeInterview(); + + // Resumes an existing interview by loading its transcript. + Q_INVOKABLE void openSession(const QString& interviewId); + + // Milliseconds before a scripted demo reply appears (tests shorten it). + void setFallbackReplyDelay(int milliseconds) { m_fallbackReplyDelayMs = milliseconds; } + +public slots: + // Starts a freshly created interview (wired to SetupViewModel::interviewStarted). + void beginSession(const QString& interviewId, const QString& direction, const QString& level, + const QString& language, const QString& firstQuestion, bool offline); + +signals: + void sessionChanged(); + void messagesChanged(); + void busyChanged(); + void completingChanged(); + void errorMessageChanged(); + void elapsedChanged(); + void interviewCompleted(const QString& interviewId); + +private: + void resetSession(const QString& interviewId, const QString& direction, const QString& level, + const QString& language, bool offline); + void appendMessage(const QString& role, const QString& content); + void appendWelcome(); + void scheduleFallbackReply(int answersBefore); + // Keeps a finished local interview in the demo history. + void recordLocalInterview() const; + void setBusy(bool busy); + void setCompleting(bool completing); + void setErrorMessage(const QString& message); + + std::shared_ptr m_interviewService; + NavigationViewModel* m_navigation; + MessageListModel m_messages; + QTimer m_clock; + + QString m_interviewId; + QString m_direction; + QString m_level; + QString m_language; + QString m_errorMessage; + std::string m_startedAt; + // Incremented for every new session so late replies of an old one are ignored. + int m_sessionToken{0}; + int m_elapsedSeconds{0}; + int m_fallbackReplyDelayMs{900}; + bool m_offline{false}; + bool m_completed{false}; + bool m_isBusy{false}; + bool m_isCompleting{false}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/DashboardViewModel.hpp b/apps/desktop/include/viewmodels/DashboardViewModel.hpp new file mode 100644 index 0000000..fbca75b --- /dev/null +++ b/apps/desktop/include/viewmodels/DashboardViewModel.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "services/InterviewService.hpp" +#include "viewmodels/InterviewListModel.hpp" +#include "viewmodels/ViewModelSupport.hpp" + +namespace devdialogue::viewmodels { + +// Candidate dashboard: KPI statistics and the interview history +// (port of the data side of the web DashboardView.tsx). +class DashboardViewModel : public QObject, public support::BackendAware { + Q_OBJECT + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) + Q_PROPERTY(int totalInterviews READ totalInterviews NOTIFY statsChanged) + Q_PROPERTY(double averageScore READ averageScore NOTIFY statsChanged) + Q_PROPERTY(QString averageScoreText READ averageScoreText NOTIFY statsChanged) + Q_PROPERTY(int dailyInterviewsCount READ dailyInterviewsCount NOTIFY statsChanged) + Q_PROPERTY(int dailyLimit READ dailyLimit NOTIFY statsChanged) + Q_PROPERTY(int remainingToday READ remainingToday NOTIFY statsChanged) + Q_PROPERTY(bool isDemoData READ isDemoData NOTIFY statsChanged) + Q_PROPERTY(QAbstractItemModel* interviews READ interviews CONSTANT) + Q_PROPERTY(int interviewCount READ interviewCount NOTIFY interviewsChanged) + +public: + explicit DashboardViewModel(std::shared_ptr interviewService, + QObject* parent = nullptr); + + bool loading() const { return m_loading; } + int totalInterviews() const { return m_stats.totalInterviews; } + double averageScore() const { return m_stats.averageScore; } + // "82.5" or "77"; empty while there is no score yet. + QString averageScoreText() const; + int dailyInterviewsCount() const { return m_stats.dailyInterviewsCount; } + int dailyLimit() const { return m_stats.dailyLimit; } + int remainingToday() const { return m_stats.remainingToday; } + bool isDemoData() const { return m_isDemoData; } + QAbstractItemModel* interviews() { return &m_interviews; } + int interviewCount() const { return m_interviews.count(); } + + // Loads the statistics and the history. If the backend cannot be + // reached the screen shows the same sample data as the web client. + Q_INVOKABLE void refresh(); + +signals: + void loadingChanged(); + void statsChanged(); + void interviewsChanged(); + +private: + void setLoading(bool value); + void apply(const models::UserDashboardStats& stats, std::vector interviews, + bool isDemo); + + std::shared_ptr m_interviewService; + InterviewListModel m_interviews; + models::UserDashboardStats m_stats; + bool m_loading{false}; + bool m_isDemoData{false}; + int m_generation{0}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/DemoData.hpp b/apps/desktop/include/viewmodels/DemoData.hpp new file mode 100644 index 0000000..9aa0900 --- /dev/null +++ b/apps/desktop/include/viewmodels/DemoData.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include + +#include "models/ApiContracts.hpp" + +// Local data shown when the backend cannot be reached. +// +// The demo has to stay consistent with itself: the history lists two sample +// interviews plus every interview finished offline in this run, the numbers +// on Home are counted from that list, and a report always belongs to the +// interview it is opened for. A report for an offline interview is built +// from its own transcript; with no evaluator available, each answer is +// scored by how detailed it is and the report says so. +// +// This is a presentation-level stand-in only. The embedded offline interview +// engine replaces it for real offline sessions. +namespace devdialogue::viewmodels::demo { + +// --- History --------------------------------------------------------------- + +// Remembers an interview finished without the server (kept in memory for the +// lifetime of the app). Recording the same id again replaces the entry. +void recordFinishedInterview(const models::InterviewDetail& interview); +// The recorded interview with this id, or nullptr. +const models::InterviewDetail* finishedInterview(const QString& interviewId); +// Forgets the recorded interviews (used by tests). +void clearFinishedInterviews(); + +// Sample interviews and recorded ones, newest first. +std::vector interviews(); +// Counted from interviews(). +models::UserDashboardStats dashboardStats(); + +// --- Reports --------------------------------------------------------------- + +// Report for an interview of the demo history. Sample interviews get their +// sample report in `uiLanguage`; recorded ones are scored from their +// transcript in the interview language. Unknown ids get an empty report. +models::InterviewFeedbackReport report(const QString& interviewId, const QString& uiLanguage); +// Report built from a transcript, scored by the detail of each answer. +models::InterviewFeedbackReport reportFromTranscript(const QString& direction, + const std::vector& transcript, + const QString& language); + +// --- Interview room and question bank ---------------------------------------- + +// `language` is "uk" or "en"; anything else falls back to English. +std::vector questions(const QString& language); + +QString chatWelcome(const QString& direction, const QString& level, const QString& language); +// Follow-up questions of the track, then a closing line. +QStringList chatReplies(const QString& direction, const QString& language); + +} // namespace devdialogue::viewmodels::demo diff --git a/apps/desktop/include/viewmodels/FormValidator.hpp b/apps/desktop/include/viewmodels/FormValidator.hpp new file mode 100644 index 0000000..b037a75 --- /dev/null +++ b/apps/desktop/include/viewmodels/FormValidator.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace devdialogue::viewmodels { + +// Input rules of the sign-up and profile forms, kept out of QML so they can +// be unit tested. The rules match the web client's login page. +class FormValidator : public QObject { + Q_OBJECT + +public: + explicit FormValidator(QObject* parent = nullptr); + + // At least 3 characters; English letters, digits and underscores only. + Q_INVOKABLE static bool isValidNickname(const QString& text); + + // 8 to 72 characters with at least one letter and one digit. + Q_INVOKABLE static bool isValidPassword(const QString& text); + + // Loose shape check (something@domain.tld); the server has the final say. + Q_INVOKABLE static bool isValidEmail(const QString& text); +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/InterviewListModel.hpp b/apps/desktop/include/viewmodels/InterviewListModel.hpp new file mode 100644 index 0000000..a95dbe9 --- /dev/null +++ b/apps/desktop/include/viewmodels/InterviewListModel.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +#include "models/ApiContracts.hpp" + +namespace devdialogue::viewmodels { + +// Rows of the dashboard history table. +class InterviewListModel : public QAbstractListModel { + Q_OBJECT + +public: + enum Roles { + InterviewIdRole = Qt::UserRole + 1, + DateTextRole, + DirectionRole, + LevelRole, + StatusRole, + IsCompletedRole, + HasScoreRole, + ScoreRole + }; + + explicit InterviewListModel(QObject* parent = nullptr); + + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + void setInterviews(std::vector interviews); + int count() const { return static_cast(m_interviews.size()); } + +private: + std::vector m_interviews; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/MessageListModel.hpp b/apps/desktop/include/viewmodels/MessageListModel.hpp new file mode 100644 index 0000000..a1e9214 --- /dev/null +++ b/apps/desktop/include/viewmodels/MessageListModel.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "models/ApiContracts.hpp" + +namespace devdialogue::viewmodels { + +// Chat transcript of the interview room. System messages never reach the +// screen, so they are dropped when a transcript is loaded. +class MessageListModel : public QAbstractListModel { + Q_OBJECT + +public: + enum Roles { + RoleRole = Qt::UserRole + 1, + ContentRole, + TimeTextRole + }; + + explicit MessageListModel(QObject* parent = nullptr); + + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + void clear(); + void setMessages(const std::vector& messages); + // Appends a message stamped with the current time. + void append(const QString& role, const QString& content); + + int count() const { return static_cast(m_messages.size()); } + int userMessageCount() const; + const std::vector& messages() const { return m_messages; } + +private: + std::vector m_messages; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/QuestionListModel.hpp b/apps/desktop/include/viewmodels/QuestionListModel.hpp new file mode 100644 index 0000000..6b4bccd --- /dev/null +++ b/apps/desktop/include/viewmodels/QuestionListModel.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "models/ApiContracts.hpp" + +namespace devdialogue::viewmodels { + +// Rows of the admin question bank table. +class QuestionListModel : public QAbstractListModel { + Q_OBJECT + +public: + enum Roles { + QuestionIdRole = Qt::UserRole + 1, + DirectionRole, + LevelRole, + TopicRole, + QuestionTextRole, + IsActiveRole + }; + + explicit QuestionListModel(QObject* parent = nullptr); + + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + void setQuestions(std::vector questions); + void prepend(models::QuestionBankItem question); + bool removeById(const QString& id); + // Removes the question and hands it back with the row it was in. + std::optional> takeById(const QString& id); + // Puts a question back at the row (clamped to the list). + void insertAt(int row, models::QuestionBankItem question); + bool contains(const QString& id) const { return indexOfId(id) >= 0; } + // Returns the previous state, or nothing if the question is not in the list. + std::optional setActive(const QString& id, bool active); + // Replaces the row with the same id (after the server confirmed an edit). + void replace(const models::QuestionBankItem& question); + + int count() const { return static_cast(m_questions.size()); } + +private: + int indexOfId(const QString& id) const; + + std::vector m_questions; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/ReportViewModel.hpp b/apps/desktop/include/viewmodels/ReportViewModel.hpp new file mode 100644 index 0000000..dd3b7f9 --- /dev/null +++ b/apps/desktop/include/viewmodels/ReportViewModel.hpp @@ -0,0 +1,92 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "services/InterviewService.hpp" +#include "viewmodels/ViewModelSupport.hpp" + +namespace devdialogue::viewmodels { + +// Performance report of a finished interview (port of the data side of the +// web PerformanceReport.tsx). +class ReportViewModel : public QObject, public support::BackendAware { + Q_OBJECT + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) + Q_PROPERTY(bool hasReport READ hasReport NOTIFY reportChanged) + Q_PROPERTY(bool isDemoData READ isDemoData NOTIFY reportChanged) + Q_PROPERTY(int score READ score NOTIFY reportChanged) + Q_PROPERTY(QString summary READ summary NOTIFY reportChanged) + Q_PROPERTY(QStringList strengths READ strengths NOTIFY reportChanged) + Q_PROPERTY(QStringList weaknesses READ weaknesses NOTIFY reportChanged) + // Each entry: { topic, resource } + Q_PROPERTY(QVariantList recommendations READ recommendations NOTIFY reportChanged) + // Each entry: { question, score, comment } + Q_PROPERTY(QVariantList questionScores READ questionScores NOTIFY reportChanged) + // Which interview the report is about: "frontend", "junior", "16.11.2026 10:49". + Q_PROPERTY(QString direction READ direction NOTIFY reportChanged) + Q_PROPERTY(QString level READ level NOTIFY reportChanged) + Q_PROPERTY(QString dateText READ dateText NOTIFY reportChanged) + // Why the report of a server interview could not be loaded; empty otherwise. + Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY reportChanged) + // Language of the sample report shown when the backend is unreachable. + Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUiLanguage NOTIFY uiLanguageChanged) + +public: + explicit ReportViewModel(std::shared_ptr interviewService, + QObject* parent = nullptr); + + bool loading() const { return m_loading; } + bool hasReport() const { return m_hasReport; } + bool isDemoData() const { return m_isDemoData; } + int score() const { return m_report.score; } + QString summary() const { return QString::fromStdString(m_report.summary); } + QStringList strengths() const; + QStringList weaknesses() const; + QVariantList recommendations() const; + QVariantList questionScores() const; + QString direction() const { return m_direction; } + QString level() const { return m_level; } + QString dateText() const { return m_dateText; } + QString errorMessage() const { return m_errorMessage; } + QString uiLanguage() const { return m_uiLanguage; } + void setUiLanguage(const QString& language); + + // Loads the feedback of the given interview. Demo and offline interviews + // come from the demo history; an interview the server has not evaluated + // yet is scored from its transcript. A server interview that cannot be + // fetched sets errorMessage instead of showing a report. + Q_INVOKABLE void load(const QString& interviewId); + +signals: + void loadingChanged(); + void reportChanged(); + void uiLanguageChanged(); + +private: + void setLoading(bool value); + void apply(const models::InterviewFeedbackReport& report, bool isDemo); + void applyDemo(const QString& interviewId); + void fail(const QString& message); + void setContext(const models::InterviewSummary& interview); + + std::shared_ptr m_interviewService; + models::InterviewFeedbackReport m_report; + QString m_uiLanguage{QStringLiteral("en")}; + QString m_interviewId; + QString m_direction; + QString m_level; + QString m_dateText; + QString m_errorMessage; + int m_generation{0}; + bool m_loading{false}; + bool m_hasReport{false}; + bool m_isDemoData{false}; + // A sample report of the demo history follows the interface language. + bool m_followsUiLanguage{false}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/SettingsViewModel.hpp b/apps/desktop/include/viewmodels/SettingsViewModel.hpp new file mode 100644 index 0000000..7273f55 --- /dev/null +++ b/apps/desktop/include/viewmodels/SettingsViewModel.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include + +#include "services/AuthService.hpp" + +namespace devdialogue::viewmodels { + +// Read-only view of the signed-in account for the sidebar and the account +// page. Profile editing is not offered: the backend has no endpoint for it. +class SettingsViewModel : public QObject { + Q_OBJECT + Q_PROPERTY(QString displayName READ displayName NOTIFY profileChanged) + Q_PROPERTY(QString email READ email NOTIFY profileChanged) + Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY profileChanged) + Q_PROPERTY(QString role READ role NOTIFY profileChanged) + Q_PROPERTY(bool isDemoAccount READ isDemoAccount NOTIFY profileChanged) + +public: + explicit SettingsViewModel(std::shared_ptr authService, QObject* parent = nullptr); + + // Full name, or the part of the email before "@" when there is none. + QString displayName() const; + QString email() const; + QString avatarUrl() const; + // "admin" or "user" + QString role() const; + // True for the offline demo accounts created by AuthService::mockLogin. + bool isDemoAccount() const; + +signals: + void profileChanged(); + +private: + std::shared_ptr m_authService; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/SetupViewModel.hpp b/apps/desktop/include/viewmodels/SetupViewModel.hpp new file mode 100644 index 0000000..e916676 --- /dev/null +++ b/apps/desktop/include/viewmodels/SetupViewModel.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include + +#include "services/InterviewService.hpp" +#include "viewmodels/NavigationViewModel.hpp" +#include "viewmodels/ViewModelSupport.hpp" + +namespace devdialogue::viewmodels { + +// Interview configuration screen (port of the web InterviewSetup.tsx): +// holds the chosen track, level and language and starts the session. +class SetupViewModel : public QObject, public support::BackendAware { + Q_OBJECT + Q_PROPERTY(QString direction READ direction WRITE setDirection NOTIFY directionChanged) + Q_PROPERTY(QString level READ level WRITE setLevel NOTIFY levelChanged) + Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) + Q_PROPERTY(bool isBusy READ isBusy NOTIFY busyChanged) + Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) + +public: + explicit SetupViewModel(std::shared_ptr interviewService, + NavigationViewModel* navigation, QObject* parent = nullptr); + + QString direction() const { return m_direction; } + void setDirection(const QString& value); + QString level() const { return m_level; } + void setLevel(const QString& value); + QString language() const { return m_language; } + void setLanguage(const QString& value); + bool isBusy() const { return m_isBusy; } + QString errorMessage() const { return m_errorMessage; } + + // Creates the interview and opens the chat room. If the backend is + // unreachable a local demo session is started instead, like on the web. + Q_INVOKABLE void start(); + +signals: + void directionChanged(); + void levelChanged(); + void languageChanged(); + void busyChanged(); + void errorMessageChanged(); + // Emitted right before navigating to the chat room. `firstQuestion` is + // empty and `offline` is true for a local demo session. + void interviewStarted(const QString& interviewId, const QString& direction, const QString& level, + const QString& language, const QString& firstQuestion, bool offline); + +private: + void setBusy(bool busy); + void setErrorMessage(const QString& message); + void launch(const QString& interviewId, const QString& firstQuestion, bool offline); + + std::shared_ptr m_interviewService; + NavigationViewModel* m_navigation; + QString m_direction{QStringLiteral("frontend")}; + QString m_level{QStringLiteral("junior")}; + QString m_language{QStringLiteral("uk")}; + QString m_errorMessage; + bool m_isBusy{false}; +}; + +} // namespace devdialogue::viewmodels diff --git a/apps/desktop/include/viewmodels/ViewModelSupport.hpp b/apps/desktop/include/viewmodels/ViewModelSupport.hpp new file mode 100644 index 0000000..b305d84 --- /dev/null +++ b/apps/desktop/include/viewmodels/ViewModelSupport.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include +#include +#include +#include + +#include + +#include "models/ApiContracts.hpp" + +// Small helpers shared by the screen view models. +namespace devdialogue::viewmodels::support { + +// Contract enums travel as lower-case strings ("frontend", "junior", ...). +// The QML layer works with the same strings, so conversion goes through the +// JSON serializers of ApiContracts.hpp to stay in sync with the API. +template +QString enumToString(TEnum value) { + const nlohmann::json json = value; + return QString::fromStdString(json.get()); +} + +template +TEnum enumFromString(const QString& text) { + return nlohmann::json(text.toStdString()).get(); +} + +inline QDateTime parseTimestamp(const std::string& iso) { + const QString text = QString::fromStdString(iso); + QDateTime parsed = QDateTime::fromString(text, Qt::ISODateWithMs); + if (!parsed.isValid()) { + parsed = QDateTime::fromString(text, Qt::ISODate); + } + return parsed; +} + +// "12.11.2026 13:28" in the user's time zone. Numeric on purpose: month +// names would follow the system locale, not the interface language. +inline QString formatDateTime(const std::string& iso) { + const QDateTime parsed = parseTimestamp(iso); + if (!parsed.isValid()) { + return QString::fromStdString(iso); + } + return parsed.toLocalTime().toString(QStringLiteral("dd.MM.yyyy HH:mm")); +} + +// "13:28" in the user's time zone. +inline QString formatTime(const std::string& iso) { + const QDateTime parsed = parseTimestamp(iso); + if (!parsed.isValid()) { + return QString(); + } + return parsed.toLocalTime().toString(QStringLiteral("HH:mm")); +} + +inline std::string nowIso() { + return QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs).toStdString(); +} + +// Lets a view model skip a request it already knows will fail. The probe is +// optional; without one every request is attempted. +class BackendAware { +public: + using Probe = std::function; + + void setBackendOnlineProbe(Probe probe) { m_probe = std::move(probe); } + +protected: + bool backendLikelyOnline() const { return !m_probe || m_probe(); } + +private: + Probe m_probe; +}; + +} // namespace devdialogue::viewmodels::support diff --git a/apps/desktop/qml/Main.qml b/apps/desktop/qml/Main.qml index 9262df9..a987965 100644 --- a/apps/desktop/qml/Main.qml +++ b/apps/desktop/qml/Main.qml @@ -1,95 +1,234 @@ +import QtCore import QtQuick -import QtQuick.Controls +import QtQuick.Controls.Basic import QtQuick.Layouts import DevDialogue.App +// Application window. Signed out it shows the sign-in screen; signed in it +// is a sidebar plus the current screen in a rounded content panel. A short +// intro plays on start-up while the saved session is restored. ApplicationWindow { id: rootWindow + visible: true - width: 1200 - height: 800 - minimumWidth: 960 - minimumHeight: 640 - title: qsTr("Dev Dialogue — AI Interview Simulator (C++ Desktop)") - color: Theme.backgroundPrimary - - Navbar { - id: navbar - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - z: 10 - } - - StackLayout { - id: viewStack - anchors.top: navbar.bottom - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - currentIndex: navVM.currentViewIndex - - LandingView {} - - // Placeholder for Dashboard - Rectangle { - color: Theme.backgroundPrimary - Text { - anchors.centerIn: parent - text: "Dashboard View (Milestone 4)" - color: Theme.textSecondary - font.pixelSize: 18 - font.family: Theme.fontSans - } + width: 1280 + height: 820 + minimumWidth: 1024 + minimumHeight: 680 + title: "Dev Dialogue" + color: Theme.zinc950 + font.family: Theme.fontSans + + // The account page is not part of NavigationViewModel; it is a local + // overlay page that closes whenever the view model navigates. + property bool accountOpen: false + + // Stack index per NavigationViewModel::ViewIndex. Landing (0) has no + // screen in the app and shows Home. + readonly property int pageIndex: accountOpen ? 6 + : (navVM.currentViewIndex === 0 ? 1 : navVM.currentViewIndex) + + readonly property string sidebarSection: { + if (accountOpen) return "account" + switch (pageIndex) { + case 1: return "home" + case 2: return "setup" + case 3: return "session" + case 4: return "home" + case 5: return "admin" + default: return "" } + } - // Placeholder for Setup - Rectangle { - color: Theme.backgroundPrimary - Text { - anchors.centerIn: parent - text: "Interview Setup View (Milestone 5)" - color: Theme.textSecondary - font.pixelSize: 18 - font.family: Theme.fontSans - } + function go(target) { + accountOpen = target === "account" + switch (target) { + case "home": navVM.navigateToDashboard(); break + case "setup": navVM.navigateToSetup(); break + case "session": + if (chatVM.hasActiveSession) + navVM.navigateToChat(chatVM.interviewId) + break + case "admin": + if (authVM.isAdmin && authVM.isAdminViewActive) + navVM.navigateToAdmin() + break } + } - // Placeholder for Chat - Rectangle { - color: Theme.backgroundPrimary - Text { - anchors.centerIn: parent - text: "Chat Room View (Milestone 5)" - color: Theme.textSecondary - font.pixelSize: 18 - font.family: Theme.fontSans + Connections { + target: navVM + function onCurrentViewIndexChanged() { rootWindow.accountOpen = false } + } + + // Leaving the admin view (or losing the role) must not leave the + // question bank on screen. + Connections { + target: authVM + function onAdminViewChanged() { + if (!authVM.isAdminViewActive && navVM.currentViewIndex === 5) + navVM.navigateToDashboard() + } + function onAuthStateChanged() { + if (!authVM.isAuthenticated) { + rootWindow.accountOpen = false + navVM.navigateToDashboard() + } else if (!authVM.isAdmin && navVM.currentViewIndex === 5) { + navVM.navigateToDashboard() } } + function onErrorOccurred(error) { + if (error !== "" && authVM.isAuthenticated) + toast.show(error, "info") + } + } - // Placeholder for Report - Rectangle { - color: Theme.backgroundPrimary - Text { - anchors.centerIn: parent - text: "Scorecard Report View (Milestone 6)" - color: Theme.textSecondary - font.pixelSize: 18 - font.family: Theme.fontSans - } + // Window size and sidebar state survive restarts. + Settings { + category: "window" + property alias width: rootWindow.width + property alias height: rootWindow.height + property alias sidebarExpanded: sidebar.expanded + } + + // Sample content shown without a backend follows the interface language. + Binding { target: reportVM; property: "uiLanguage"; value: I18n.language } + Binding { target: adminVM; property: "uiLanguage"; value: I18n.language } + + Component.onCompleted: { + if (navVM.currentViewIndex === 0) + navVM.navigateToDashboard() + } + + // ---------------------------------------------------------- Shortcuts + Shortcut { + sequence: "Ctrl+1" + enabled: authVM.isAuthenticated + onActivated: rootWindow.go("home") + } + Shortcut { + sequences: ["Ctrl+N", "Ctrl+2"] + enabled: authVM.isAuthenticated + onActivated: rootWindow.go("setup") + } + Shortcut { + sequence: "Ctrl+3" + enabled: authVM.isAuthenticated && chatVM.hasActiveSession + onActivated: rootWindow.go("session") + } + Shortcut { + sequence: "Ctrl+," + enabled: authVM.isAuthenticated + onActivated: rootWindow.go("account") + } + Shortcut { + sequence: "Ctrl+B" + enabled: authVM.isAuthenticated + onActivated: sidebar.expanded = !sidebar.expanded + } + + // ---------------------------------------------------------- Backdrop + GlowBlob { + width: 900 + height: 520 + x: parent.width * 0.55 - width / 2 + y: -300 + color: Theme.blue600 + strength: 0.10 + } + + // ------------------------------------------------------------- Shell + Item { + id: shell + anchors.fill: parent + anchors.margins: Theme.windowGap + visible: authVM.isAuthenticated + + Sidebar { + id: sidebar + anchors.left: parent.left + anchors.top: parent.top + anchors.bottom: parent.bottom + current: rootWindow.sidebarSection + onNavigate: (target) => rootWindow.go(target) } - // Placeholder for Admin Rectangle { - color: Theme.backgroundPrimary - Text { - anchors.centerIn: parent - text: "Admin Question Bank View (Milestone 7)" - color: Theme.textSecondary - font.pixelSize: 18 - font.family: Theme.fontSans + id: contentPanel + anchors.left: sidebar.right + anchors.leftMargin: Theme.windowGap + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + radius: Theme.radiusXl + color: "#0e0e11" + border.width: 1 + border.color: Theme.borderGlass + clip: true + + StackLayout { + id: pages + anchors.fill: parent + anchors.margins: 1 + currentIndex: rootWindow.pageIndex + + Item {} // 0: Landing, not used in the app + DashboardView {} // 1 + SetupView {} // 2 + ChatRoomView {} // 3 + ReportView {} // 4 + AdminView {} // 5 + AccountView {} // 6: local page, see accountOpen } } } -} + LoginView { + anchors.fill: parent + visible: !authVM.isAuthenticated + onNotify: (message, tone) => toast.show(message, tone) + } + + Toast { + id: toast + z: 2000 + } + Connections { + target: adminVM + function onQuestionDeleted(topic) { + toast.show(qsTr("Question \u201c%1\u201d deleted").arg(topic), "info", qsTr("Undo"), + () => adminVM.undoDelete()) + } + function onQuestionDeleteFailed(topic, reason) { + toast.show(reason !== "" + ? qsTr("\u201c%1\u201d was not deleted: %2").arg(topic).arg(reason) + : qsTr("\u201c%1\u201d was not deleted: the server could not be reached.").arg(topic), + "error") + } + function onDeletesSettled() { + if (rootWindow.closeAfterDeletes) + rootWindow.close() + } + } + + // A question deleted moments ago is still inside its undo window and the + // server does not know yet. Closing sends the delete and waits for the + // answer (a few seconds at most) so the question does not come back. + property bool closeAfterDeletes: false + onClosing: (close) => { + if (!closeAfterDeletes && adminVM.sendPendingDeletes()) { + close.accepted = false + closeAfterDeletes = true + closeAnyway.start() + } + } + Timer { + id: closeAnyway + interval: 4000 + onTriggered: rootWindow.close() + } + + SplashOverlay { + anchors.fill: parent + } +} diff --git a/apps/desktop/qml/components/AlertBox.qml b/apps/desktop/qml/components/AlertBox.qml new file mode 100644 index 0000000..b819467 --- /dev/null +++ b/apps/desktop/qml/components/AlertBox.qml @@ -0,0 +1,64 @@ +import QtQuick +import QtQuick.Layouts +import DevDialogue.App + +// Inline message box for form errors, confirmations and hints. +Rectangle { + id: root + + property string text + property string tone: "error" // error | success | info + property string title + + readonly property var tones: ({ + error: { base: Theme.red500, deep: Theme.red950, fg: Theme.red200, icon: Theme.red400, name: "circle-alert" }, + success: { base: Theme.emerald500, deep: Theme.emerald950, fg: Theme.emerald300, icon: Theme.emerald400, name: "circle-check" }, + info: { base: Theme.blue500, deep: Theme.blue950, fg: Theme.zinc400, icon: Theme.blue400, name: "info" } + }) + readonly property var toneColors: tones[tone] !== undefined ? tones[tone] : tones.error + + implicitHeight: row.implicitHeight + 28 + radius: Theme.radiusMd + color: tone === "info" ? Theme.alpha(Theme.blue500, 0.05) : Theme.alpha(toneColors.deep, 0.3) + border.width: 1 + border.color: Theme.alpha(toneColors.base, tone === "info" ? 0.2 : 0.3) + + RowLayout { + id: row + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.margins: 14 + spacing: 10 + + Icon { + Layout.alignment: Qt.AlignTop + Layout.topMargin: 2 + name: root.toneColors.name + size: 16 + color: root.toneColors.icon + } + ColumnLayout { + Layout.fillWidth: true + spacing: 4 + + AppText { + Layout.fillWidth: true + visible: root.title !== "" + text: root.title + color: Theme.blue300 + font.pixelSize: Typography.xs + font.weight: Typography.semibold + wrapMode: Text.WordWrap + } + AppText { + Layout.fillWidth: true + text: root.text + color: root.toneColors.fg + font.pixelSize: root.tone === "info" ? Typography.tiny : Typography.xs + lineHeight: Typography.leadingRelaxed + wrapMode: Text.WordWrap + } + } + } +} diff --git a/apps/desktop/qml/components/AppPage.qml b/apps/desktop/qml/components/AppPage.qml new file mode 100644 index 0000000..8e1ef5c --- /dev/null +++ b/apps/desktop/qml/components/AppPage.qml @@ -0,0 +1,147 @@ +import QtQuick +import QtQuick.Controls.Basic +import QtQuick.Layouts +import DevDialogue.App + +// Container for one screen of the app: a header with the title, optional +// badge and actions, and a body that fills the rest of the window. With +// `scrollable` the body scrolls; otherwise children size themselves to the +// available height (tables and chats manage their own scrolling). +Item { + id: page + + property string title + property string subtitle + property string badgeText // e.g. "Demo data" + property alias actions: actionsRow.data + property alias headerExtra: extraRow.data + default property alias content: body.data + property bool scrollable: false + property int bodySpacing: 20 + property int bodyPadding: 28 + // Set by the owner (StackLayout.isCurrentItem) to replay the entrance. + property bool active: true + readonly property real bodyWidth: body.width + + function scrollToTop() { + if (scroller.visible) + scroller.contentY = 0 + } + + onActiveChanged: { + if (active) { + scrollToTop() + entrance.restart() + } + } + + // ------------------------------------------------------------- Header + Item { + id: header + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + height: 84 + + RowLayout { + anchors.fill: parent + anchors.leftMargin: page.bodyPadding + anchors.rightMargin: page.bodyPadding + spacing: 16 + + ColumnLayout { + Layout.fillWidth: true + spacing: 4 + + RowLayout { + spacing: 10 + Layout.fillWidth: true + + AppText { + Layout.maximumWidth: header.width * 0.6 + text: page.title + font.pixelSize: Typography.xl2 + font.weight: Typography.bold + font.letterSpacing: Typography.tracking(Typography.xl2, Typography.trackingTight) + elide: Text.ElideRight + } + Badge { + visible: page.badgeText !== "" + tone: "amber" + pill: true + dot: true + text: page.badgeText + fontSize: Typography.tiny + } + RowLayout { + id: extraRow + spacing: 8 + } + } + AppText { + Layout.fillWidth: true + visible: page.subtitle !== "" + text: page.subtitle + color: Theme.zinc400 + elide: Text.ElideRight + } + } + + RowLayout { + id: actionsRow + spacing: 10 + } + } + + Rectangle { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + height: 1 + color: Theme.borderFaint + } + } + + // --------------------------------------------------------------- Body + Item { + id: bodyArea + anchors.top: header.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + + Flickable { + id: scroller + anchors.fill: parent + visible: page.scrollable + contentWidth: width + contentHeight: page.scrollable ? body.implicitHeight + page.bodyPadding * 2 : height + clip: true + boundsBehavior: Flickable.StopAtBounds + ScrollBar.vertical: ThemedScrollBar {} + } + + ColumnLayout { + id: body + parent: page.scrollable ? scroller.contentItem : bodyArea + x: page.bodyPadding + y: page.bodyPadding + entranceOffset + width: (page.scrollable ? scroller.width : bodyArea.width) - page.bodyPadding * 2 + height: page.scrollable ? implicitHeight : bodyArea.height - page.bodyPadding * 2 + spacing: page.bodySpacing + property real entranceOffset: 0 + } + } + + ParallelAnimation { + id: entrance + NumberAnimation { + target: body; property: "opacity"; from: 0; to: 1 + duration: Theme.durationEnter; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring + } + NumberAnimation { + target: body; property: "entranceOffset"; from: 8; to: 0 + duration: Theme.durationEnter; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring + } + } +} diff --git a/apps/desktop/qml/components/AppText.qml b/apps/desktop/qml/components/AppText.qml new file mode 100644 index 0000000..70938e6 --- /dev/null +++ b/apps/desktop/qml/components/AppText.qml @@ -0,0 +1,10 @@ +import QtQuick +import DevDialogue.App + +// Base sans-serif text with the body defaults of the web client. +Text { + color: Theme.textPrimary + font.family: Theme.fontSans + font.pixelSize: Typography.sm + textFormat: Text.PlainText +} diff --git a/apps/desktop/qml/components/AppToolTip.qml b/apps/desktop/qml/components/AppToolTip.qml new file mode 100644 index 0000000..47c332d --- /dev/null +++ b/apps/desktop/qml/components/AppToolTip.qml @@ -0,0 +1,43 @@ +import QtQuick +import QtQuick.Controls.Basic +import DevDialogue.App + +// Tooltip in the app's own dark style; the stock Basic tooltip is a white +// box that belongs to no theme. Declare it inside the item it describes. +// side: "top" (default) or "right" for the collapsed sidebar rail. +ToolTip { + id: tip + + property string side: "top" + + delay: 500 + leftPadding: 10 + rightPadding: 10 + topPadding: 6 + bottomPadding: 6 + margins: 8 + + x: side === "right" && parent ? parent.width + 10 : (parent ? (parent.width - width) / 2 : 0) + y: side === "right" && parent ? (parent.height - height) / 2 : -height - 8 + + contentItem: AppText { + text: tip.text + color: Theme.zinc200 + font.pixelSize: Typography.xs + wrapMode: Text.Wrap + } + + background: Rectangle { + radius: Theme.radiusSm + color: Theme.zinc850 + border.width: 1 + border.color: Theme.borderStrong + } + + enter: Transition { + NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 120; easing.type: Easing.OutCubic } + } + exit: Transition { + NumberAnimation { property: "opacity"; from: 1; to: 0; duration: 80 } + } +} diff --git a/apps/desktop/qml/components/Badge.qml b/apps/desktop/qml/components/Badge.qml new file mode 100644 index 0000000..827c286 --- /dev/null +++ b/apps/desktop/qml/components/Badge.qml @@ -0,0 +1,72 @@ +import QtQuick +import QtQuick.Layouts +import DevDialogue.App + +// Small label chip: status badges, track tags, pill headers. +// `tone` picks one of the tinted colour sets used on the web +// (bg--500/10 + border--500/20..30 + text--300/400). +Rectangle { + id: badge + + property string text + property string tone: "blue" // blue | emerald | amber | rose | red | neutral + property bool mono: false + property bool caps: false + property bool pill: false + property string iconName + property real iconSize: 14 + property bool dot: false + property int fontSize: Typography.xs + property int fontWeight: Typography.medium + property int horizontalPadding: 8 + property int verticalPadding: 2 + property real fillOpacity: 0.1 + property real strokeOpacity: 0.2 + + readonly property var tones: ({ + blue: { base: Theme.blue500, fg: Theme.blue400 }, + emerald: { base: Theme.emerald500, fg: Theme.emerald400 }, + amber: { base: Theme.amber500, fg: Theme.amber400 }, + rose: { base: Theme.rose500, fg: Theme.rose300 }, + red: { base: Theme.red500, fg: Theme.red300 }, + neutral: { base: Theme.zinc800, fg: Theme.zinc300 } + }) + readonly property var toneColors: tones[tone] !== undefined ? tones[tone] : tones.blue + property color foreground: toneColors.fg + + implicitWidth: row.implicitWidth + horizontalPadding * 2 + implicitHeight: row.implicitHeight + verticalPadding * 2 + radius: pill ? height / 2 : Theme.radiusXs + color: tone === "neutral" ? Theme.alpha(Theme.zinc800, 0.8) : Theme.alpha(toneColors.base, fillOpacity) + border.width: 1 + border.color: tone === "neutral" ? Theme.borderFaint : Theme.alpha(toneColors.base, strokeOpacity) + + RowLayout { + id: row + anchors.centerIn: parent + spacing: 6 + + Rectangle { + visible: badge.dot + implicitWidth: 6 + implicitHeight: 6 + radius: 3 + color: badge.foreground + } + Icon { + visible: badge.iconName !== "" + name: badge.iconName + size: badge.iconSize + color: badge.foreground + } + Text { + text: badge.text + color: badge.foreground + font.family: badge.mono ? Theme.fontMono : Theme.fontSans + font.pixelSize: badge.fontSize + font.weight: badge.fontWeight + font.capitalization: badge.caps ? Font.AllUppercase : Font.MixedCase + textFormat: Text.PlainText + } + } +} diff --git a/apps/desktop/qml/components/DarkCard.qml b/apps/desktop/qml/components/DarkCard.qml new file mode 100644 index 0000000..6561773 --- /dev/null +++ b/apps/desktop/qml/components/DarkCard.qml @@ -0,0 +1,38 @@ +import QtQuick +import QtQuick.Controls.Basic +import DevDialogue.App + +// Card surface of the web client: translucent zinc fill, 1px hairline +// border, 16px radius. With `interactive` it gets the .card-interactive +// hover lift. +Pane { + id: card + + property color fillColor: Theme.surfaceCard + property color hoverFillColor: fillColor + property color strokeColor: Theme.borderGlass + property color hoverStrokeColor: strokeColor + property int cardRadius: Theme.radiusLg + property bool interactive: false + property alias gradient: surface.gradient + + padding: 20 + hoverEnabled: true + + transform: Translate { + y: card.interactive && card.hovered ? -2 : 0 + Behavior on y { + NumberAnimation { duration: Theme.durationCard; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring } + } + } + + background: Rectangle { + id: surface + radius: card.cardRadius + color: card.hovered ? card.hoverFillColor : card.fillColor + border.width: 1 + border.color: card.hovered ? card.hoverStrokeColor : card.strokeColor + Behavior on color { ColorAnimation { duration: Theme.durationCard } } + Behavior on border.color { ColorAnimation { duration: Theme.durationCard } } + } +} diff --git a/apps/desktop/qml/components/DarkTextArea.qml b/apps/desktop/qml/components/DarkTextArea.qml new file mode 100644 index 0000000..0b736d8 --- /dev/null +++ b/apps/desktop/qml/components/DarkTextArea.qml @@ -0,0 +1,73 @@ +import QtQuick +import QtQuick.Controls.Basic +import DevDialogue.App + +// Multi-line input. "chat" is the interview answer box (accent focus +// ring), "solid" matches the admin dialog textarea. +ScrollView { + id: root + + property alias text: area.text + property alias placeholderText: area.placeholderText + property alias area: area + property string appearance: "chat" + property bool invalid: false + property int trailingSpace: 0 + signal submitted() + + readonly property bool solid: appearance === "solid" + readonly property color focusColor: Theme.blue500 + + implicitHeight: solid ? 76 : 76 + clip: true + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + + background: Rectangle { + radius: root.solid ? Theme.radiusMd : Theme.radiusLg + color: root.solid ? Theme.zinc800 : Theme.alpha(Theme.zinc900, 0.7) + border.width: 1 + border.color: root.invalid + ? Theme.alpha(Theme.red500, 0.6) + : area.activeFocus + ? Theme.alpha(root.focusColor, 0.5) + : (root.solid ? Theme.zinc700 : Theme.borderGlass) + Behavior on border.color { ColorAnimation { duration: Theme.durationFast } } + + Rectangle { + anchors.fill: parent + anchors.margins: -1 + radius: parent.radius + 1 + color: "transparent" + border.width: 1 + border.color: Theme.alpha(root.focusColor, 0.4) + visible: area.activeFocus && !root.invalid + } + } + + TextArea { + id: area + leftPadding: root.solid ? 10 : 16 + rightPadding: (root.solid ? 10 : 16) + root.trailingSpace + topPadding: root.solid ? 10 : 16 + bottomPadding: root.solid ? 10 : 16 + wrapMode: TextEdit.Wrap + color: root.solid ? Theme.textOnAccent : Theme.textPrimary + placeholderTextColor: Theme.textMuted + selectionColor: Theme.alpha(Theme.blue500, 0.35) + selectedTextColor: Theme.textOnAccent + font.family: Theme.fontSans + font.pixelSize: root.solid ? Typography.xs : Typography.sm + selectByMouse: true + background: null + + // Enter submits, Shift+Enter inserts a new line (web ChatRoom). + Keys.onPressed: (event) => { + if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) + && !(event.modifiers & Qt.ShiftModifier) + && root.appearance === "chat") { + event.accepted = true + root.submitted() + } + } + } +} diff --git a/apps/desktop/qml/components/DarkTextField.qml b/apps/desktop/qml/components/DarkTextField.qml new file mode 100644 index 0000000..286e3aa --- /dev/null +++ b/apps/desktop/qml/components/DarkTextField.qml @@ -0,0 +1,98 @@ +import QtQuick +import QtQuick.Controls.Basic +import DevDialogue.App + +// Single-line input of the web forms: translucent zinc fill, hairline +// border, blue border + ring on focus, optional leading icon and a +// show/hide toggle for passwords. +TextField { + id: field + + property string leadingIcon + property bool password: false + property bool revealed: false + property bool invalid: false + // "form" = login / settings inputs, "solid" = admin dialog inputs + property string appearance: "form" + + readonly property bool solid: appearance === "solid" + + implicitHeight: solid ? 36 : 42 + leftPadding: leadingIcon !== "" ? 40 : (solid ? 10 : 14) + rightPadding: password ? 44 : (solid ? 10 : 14) + topPadding: 0 + bottomPadding: 0 + verticalAlignment: TextInput.AlignVCenter + + color: solid ? Theme.textOnAccent : Theme.textPrimary + placeholderTextColor: Theme.textMuted + selectionColor: Theme.alpha(Theme.blue500, 0.35) + selectedTextColor: Theme.textOnAccent + font.family: Theme.fontSans + font.pixelSize: solid ? Typography.xs : Typography.sm + echoMode: password && !revealed ? TextInput.Password : TextInput.Normal + passwordCharacter: "•" + selectByMouse: true + + background: Rectangle { + radius: Theme.radiusMd + color: field.solid ? Theme.zinc800 : (field.activeFocus ? Theme.zinc900 : Theme.surfaceInput) + border.width: 1 + border.color: field.invalid + ? Theme.alpha(Theme.red500, 0.6) + : field.activeFocus + ? Theme.alpha(Theme.blue500, 0.6) + : (field.solid ? Theme.zinc700 : Theme.borderGlass) + Behavior on border.color { ColorAnimation { duration: Theme.durationFast } } + Behavior on color { ColorAnimation { duration: Theme.durationFast } } + + // focus:ring-1 focus:ring-blue-500/40 + Rectangle { + anchors.fill: parent + anchors.margins: -1 + radius: parent.radius + 1 + color: "transparent" + border.width: 1 + border.color: Theme.alpha(Theme.blue500, 0.4) + visible: field.activeFocus && !field.invalid + } + } + + Icon { + visible: field.leadingIcon !== "" + name: field.leadingIcon + size: 16 + color: Theme.textMuted + x: 14 + anchors.verticalCenter: parent.verticalCenter + } + + Rectangle { + id: revealButton + visible: field.password + width: 28 + height: 28 + radius: Theme.radiusSm + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + color: revealHover.hovered ? Qt.rgba(1, 1, 1, 0.06) : "transparent" + + Icon { + anchors.centerIn: parent + name: field.revealed ? "eye-off" : "eye" + size: 16 + color: revealHover.hovered ? Theme.zinc200 : Theme.zinc400 + } + HoverHandler { id: revealHover; cursorShape: Qt.PointingHandCursor } + TapHandler { onTapped: field.revealed = !field.revealed } + Accessible.role: Accessible.Button + Accessible.name: field.revealed ? qsTr("Hide password") : qsTr("Show password") + Accessible.onPressAction: field.revealed = !field.revealed + + AppToolTip { + visible: revealHover.hovered + text: field.revealed ? qsTr("Hide password") : qsTr("Show password") + } + } +} diff --git a/apps/desktop/qml/components/GlowBlob.qml b/apps/desktop/qml/components/GlowBlob.qml new file mode 100644 index 0000000..539cc75 --- /dev/null +++ b/apps/desktop/qml/components/GlowBlob.qml @@ -0,0 +1,42 @@ +import QtQuick +import QtQuick.Shapes +import DevDialogue.App + +// Soft ambient light: an elliptical radial gradient fading to transparent. +// Stands in for the heavily blurred gradient blobs behind the web hero and +// login card. +Item { + id: root + + property color color: Theme.blue600 + property real strength: 0.2 + + Shape { + // Drawn as a circle and stretched to the item's aspect ratio. + width: root.height + height: root.height + transform: Scale { xScale: root.width / Math.max(1, root.height) } + + ShapePath { + strokeColor: "transparent" + fillGradient: RadialGradient { + centerX: root.height / 2 + centerY: root.height / 2 + centerRadius: root.height / 2 + focalX: centerX + focalY: centerY + GradientStop { position: 0.0; color: Theme.alpha(root.color, root.strength) } + GradientStop { position: 0.25; color: Theme.alpha(root.color, root.strength * 0.72) } + GradientStop { position: 0.5; color: Theme.alpha(root.color, root.strength * 0.38) } + GradientStop { position: 0.75; color: Theme.alpha(root.color, root.strength * 0.12) } + GradientStop { position: 1.0; color: Theme.alpha(root.color, 0) } + } + PathRectangle { + x: 0 + y: 0 + width: root.height + height: root.height + } + } + } +} diff --git a/apps/desktop/qml/components/Icon.qml b/apps/desktop/qml/components/Icon.qml new file mode 100644 index 0000000..cf2edca --- /dev/null +++ b/apps/desktop/qml/components/Icon.qml @@ -0,0 +1,38 @@ +import QtQuick +import QtQuick.Effects +import DevDialogue.App + +// Vector icon tinted at runtime. Icon files are drawn in white, so a full +// colorization pass turns them into any theme colour and lets the colour +// animate (hover states) without reloading the image. +Item { + id: root + + property string name + property color color: Theme.textPrimary + property real size: 16 + // Multi-colour marks (brand logos) keep their own colours. + property bool colorize: true + + implicitWidth: size + implicitHeight: size + + Image { + id: glyph + anchors.fill: parent + source: Icons.source(root.name) + sourceSize.width: Math.round(root.size * Screen.devicePixelRatio) + sourceSize.height: Math.round(root.size * Screen.devicePixelRatio) + fillMode: Image.PreserveAspectFit + smooth: true + visible: !root.colorize + } + + MultiEffect { + anchors.fill: glyph + source: glyph + visible: root.colorize + colorization: 1.0 + colorizationColor: root.color + } +} diff --git a/apps/desktop/qml/components/KpiTile.qml b/apps/desktop/qml/components/KpiTile.qml new file mode 100644 index 0000000..cdc7a00 --- /dev/null +++ b/apps/desktop/qml/components/KpiTile.qml @@ -0,0 +1,107 @@ +import QtQuick +import QtQuick.Layouts +import DevDialogue.App + +// Dashboard statistics card: mono caption with an icon, a large value and a +// one-line description. Shows a skeleton while the data is loading. +DarkCard { + id: tile + + property string caption + property string value + property string valueSuffix + property string description + property string iconName + property color iconColor: Theme.blue400 + property color valueColor: Theme.textPrimary + property bool loading: false + property int skeletonWidth: 80 + // Optional trailing item next to the value (e.g. a progress ring). + property alias accessory: accessorySlot.data + + interactive: true + padding: 20 + + ColumnLayout { + anchors.left: parent.left + anchors.right: parent.right + spacing: 0 + + RowLayout { + Layout.fillWidth: true + Layout.bottomMargin: 8 + + MonoText { + Layout.fillWidth: true + text: tile.caption + caps: true + font.weight: Typography.semibold + elide: Text.ElideRight + } + Icon { + name: tile.iconName + size: 16 + color: tile.iconColor + } + } + + RowLayout { + Layout.fillWidth: true + Layout.preferredHeight: 40 + spacing: 8 + + Skeleton { + visible: tile.loading + Layout.preferredWidth: tile.skeletonWidth + Layout.preferredHeight: 36 + } + + MonoText { + id: valueText + visible: !tile.loading + text: tile.value + color: tile.valueColor + font.pixelSize: Typography.xl3 + font.weight: Typography.extrabold + + // animate-fade-in-up when the value arrives + onVisibleChanged: if (visible) valueEntrance.restart() + transform: Translate { id: valueShift } + ParallelAnimation { + id: valueEntrance + NumberAnimation { target: valueText; property: "opacity"; from: 0; to: 1; duration: Theme.durationEnter } + NumberAnimation { + target: valueShift; property: "y"; from: 8; to: 0 + duration: Theme.durationEnter; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring + } + } + } + AppText { + visible: !tile.loading && tile.valueSuffix !== "" + Layout.alignment: Qt.AlignBaseline + text: tile.valueSuffix + color: Theme.textMuted + font.family: Theme.fontMono + font.pixelSize: Typography.sm + } + + Item { Layout.fillWidth: true } + + Item { + id: accessorySlot + visible: !tile.loading && children.length > 0 + implicitWidth: childrenRect.width + implicitHeight: childrenRect.height + } + } + + AppText { + Layout.fillWidth: true + Layout.topMargin: 4 + text: tile.description + color: Theme.textMuted + font.pixelSize: Typography.xs + elide: Text.ElideRight + } + } +} diff --git a/apps/desktop/qml/components/MessageBubble.qml b/apps/desktop/qml/components/MessageBubble.qml new file mode 100644 index 0000000..3ac23c2 --- /dev/null +++ b/apps/desktop/qml/components/MessageBubble.qml @@ -0,0 +1,120 @@ +import QtQuick +import QtQuick.Layouts +import DevDialogue.App + +// One chat message. The interviewer sits on the left in a dark bubble with +// a bot avatar, the candidate on the right in the blue accent +// gradient bubble with a user avatar. +Item { + id: root + + property string senderRole: "assistant" + property string content + property string timestamp + readonly property bool isAssistant: senderRole !== "user" + // Bubbles never exceed 82% of the row, like the web client. + readonly property real maxBubbleWidth: Math.max(160, (width - 44) * 0.82) + + implicitHeight: row.implicitHeight + + // Plain text as HTML, so the selectable text keeps the relaxed line height. + function asHtml(text) { + const escaped = text.replace(/&/g, "&").replace(//g, ">") + .replace(/\n/g, "
") + return "
" + escaped + "
" + } + + // Entrance: fade-in-up for each new message. + opacity: 0 + transform: Translate { id: shift; y: 8 } + Component.onCompleted: entrance.start() + ParallelAnimation { + id: entrance + NumberAnimation { target: root; property: "opacity"; to: 1; duration: Theme.durationEnter } + NumberAnimation { + target: shift; property: "y"; to: 0 + duration: Theme.durationEnter; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring + } + } + + RowLayout { + id: row + anchors.left: parent.left + anchors.right: parent.right + spacing: 12 + layoutDirection: root.isAssistant ? Qt.LeftToRight : Qt.RightToLeft + + Rectangle { + Layout.alignment: Qt.AlignTop + implicitWidth: 32 + implicitHeight: 32 + radius: Theme.radiusMd + color: Theme.zinc900 + border.width: 1 + border.color: Theme.borderGlass + + Icon { + anchors.centerIn: parent + name: root.isAssistant ? "bot" : "user" + size: 16 + color: root.isAssistant ? Theme.sky300 : Theme.blue300 + } + } + + Rectangle { + id: bubble + Layout.alignment: Qt.AlignTop + implicitWidth: Math.min(root.maxBubbleWidth, Math.max(body.implicitWidth, time.implicitWidth) + 32) + implicitHeight: bubbleColumn.implicitHeight + 24 + radius: Theme.radiusLg + color: root.isAssistant ? Theme.alpha(Theme.zinc900, 0.9) : "transparent" + border.width: root.isAssistant ? 1 : 0 + border.color: Theme.borderGlass + + Rectangle { + anchors.fill: parent + radius: parent.radius + visible: !root.isAssistant + gradient: Gradient { + orientation: Gradient.Horizontal + GradientStop { position: 0.0; color: Theme.blue600 } + GradientStop { position: 0.5; color: Theme.blue500 } + GradientStop { position: 1.0; color: Theme.indigo500 } + } + } + + ColumnLayout { + id: bubbleColumn + x: 16 + y: 12 + width: parent.width - 32 + spacing: 6 + + TextEdit { + id: body + Layout.fillWidth: true + text: root.asHtml(root.content) + textFormat: TextEdit.RichText + readOnly: true + selectByMouse: true + wrapMode: TextEdit.Wrap + color: root.isAssistant ? Theme.zinc200 : Theme.textOnAccent + selectionColor: root.isAssistant ? Theme.alpha(Theme.blue500, 0.45) : Theme.alpha(Theme.zinc950, 0.45) + selectedTextColor: Theme.textOnAccent + font.family: Theme.fontSans + font.pixelSize: Typography.sm + Accessible.name: root.content + HoverHandler { cursorShape: Qt.IBeamCursor } + } + MonoText { + id: time + text: root.timestamp + color: root.isAssistant ? Theme.textMuted : Theme.alpha(Theme.blue100, 0.75) + font.pixelSize: Typography.micro + } + } + } + + Item { Layout.fillWidth: true } + } +} diff --git a/apps/desktop/qml/components/ModalOverlay.qml b/apps/desktop/qml/components/ModalOverlay.qml new file mode 100644 index 0000000..f0926d2 --- /dev/null +++ b/apps/desktop/qml/components/ModalOverlay.qml @@ -0,0 +1,100 @@ +import QtQuick +import QtQuick.Controls.Basic +import QtQuick.Layouts +import DevDialogue.App + +// Full-window modal layer: dimmed backdrop, centred dialog card with the +// fade-in-up entrance, closes on Escape or a click outside the card. +// It can be declared anywhere; when opened it moves itself to the window's +// content item so it also covers the navbar. +Item { + id: overlay + + default property alias content: cardBody.data + property bool open: false + property int dialogWidth: 512 + property int dialogPadding: 28 + property int dialogRadius: Theme.radiusLg + property color dialogColor: Theme.zinc950 + property color dialogBorder: Theme.borderStrong + property real backdropOpacity: 0.8 + property bool closeOnBackdrop: true + // Height available to the dialog body (the card is capped at 90% of the window). + readonly property real maxBodyHeight: Math.max(120, height * 0.9 - dialogPadding * 2) + signal closeRequested() + + // Plain geometry instead of anchors: the dialog may be declared inside a + // layout, where it stays hidden until it is moved to the window root. + x: 0 + y: 0 + width: parent ? parent.width : 0 + height: parent ? parent.height : 0 + z: 1000 + visible: open || backdrop.opacity > 0.01 + enabled: open + + onOpenChanged: { + if (open) { + const host = overlay.ApplicationWindow.contentItem + ? overlay.ApplicationWindow.contentItem : overlay.Window.contentItem + if (host && overlay.parent !== host) + overlay.parent = host + forceActiveFocus() + cardEntrance.restart() + } + } + + Keys.onEscapePressed: closeRequested() + + Rectangle { + id: backdrop + anchors.fill: parent + color: "#000000" + opacity: overlay.open ? overlay.backdropOpacity : 0 + Behavior on opacity { NumberAnimation { duration: 180 } } + } + + // Swallows clicks, wheel and hover so the page underneath stays inert. + MouseArea { + anchors.fill: parent + hoverEnabled: true + acceptedButtons: Qt.AllButtons + onWheel: (wheel) => wheel.accepted = true + onClicked: if (overlay.closeOnBackdrop) overlay.closeRequested() + } + + Rectangle { + id: card + width: Math.min(overlay.dialogWidth, overlay.width - 32) + height: cardBody.implicitHeight + overlay.dialogPadding * 2 + anchors.horizontalCenter: parent.horizontalCenter + y: (overlay.height - height) / 2 + entranceOffset + property real entranceOffset: 0 + radius: overlay.dialogRadius + color: overlay.dialogColor + border.width: 1 + border.color: overlay.dialogBorder + opacity: overlay.open ? 1 : 0 + Behavior on opacity { NumberAnimation { duration: 180 } } + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.AllButtons + onWheel: (wheel) => wheel.accepted = true + } + + ColumnLayout { + id: cardBody + x: overlay.dialogPadding + y: overlay.dialogPadding + width: parent.width - overlay.dialogPadding * 2 + spacing: 0 + } + } + + NumberAnimation { + id: cardEntrance + target: card; property: "entranceOffset"; from: 8; to: 0 + duration: Theme.durationEnter; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring + } +} diff --git a/apps/desktop/qml/components/MonoText.qml b/apps/desktop/qml/components/MonoText.qml new file mode 100644 index 0000000..db05403 --- /dev/null +++ b/apps/desktop/qml/components/MonoText.qml @@ -0,0 +1,15 @@ +import QtQuick +import DevDialogue.App + +// Monospace text (Geist Mono) for badges, counters, timestamps and labels. +Text { + // Section labels on the web use uppercase with wide tracking. + property bool caps: false + + color: Theme.textSecondary + font.family: Theme.fontMono + font.pixelSize: Typography.xs + font.capitalization: caps ? Font.AllUppercase : Font.MixedCase + font.letterSpacing: caps ? 0.6 : 0 + textFormat: Text.PlainText +} diff --git a/apps/desktop/qml/components/Navbar.qml b/apps/desktop/qml/components/Navbar.qml deleted file mode 100644 index 2daa6f6..0000000 --- a/apps/desktop/qml/components/Navbar.qml +++ /dev/null @@ -1,124 +0,0 @@ -import QtQuick -import QtQuick.Controls -import QtQuick.Layouts -import DevDialogue.App - -Rectangle { - id: navbarRoot - height: 64 - color: Theme.backgroundSecondary - border.color: Theme.borderGlass - border.width: 1 - - RowLayout { - anchors.fill: parent - anchors.leftMargin: 24 - anchors.rightMargin: 24 - spacing: 16 - - // Brand Logo & Title - RowLayout { - spacing: 10 - - Rectangle { - width: 32 - height: 32 - radius: Theme.radiusSm - gradient: Gradient { - orientation: Gradient.Horizontal - GradientStop { position: 0.0; color: Theme.accentRose } - GradientStop { position: 1.0; color: Theme.accentIndigo } - } - - Text { - anchors.centerIn: parent - text: "DD" - font.family: Theme.fontSans - font.weight: Font.Bold - font.pixelSize: 13 - color: "#ffffff" - } - } - - Text { - text: "Dev Dialogue" - font.family: Theme.fontSans - font.weight: Font.Bold - font.pixelSize: 16 - color: Theme.textPrimary - } - - Rectangle { - radius: 4 - color: Qt.rgba(0.95, 0.25, 0.37, 0.15) - border.color: Qt.rgba(0.95, 0.25, 0.37, 0.3) - implicitWidth: badgeText.implicitWidth + 8 - implicitHeight: 18 - - Text { - id: badgeText - anchors.centerIn: parent - text: "DESKTOP" - font.family: Theme.fontMono - font.pixelSize: 9 - font.weight: Font.Bold - color: Theme.accentRose - } - } - } - - Item { Layout.fillWidth: true } - - // Navigation Links - RowLayout { - spacing: 8 - - Button { - text: qsTr("Головна") - flat: true - contentItem: Text { - text: parent.text - font.family: Theme.fontSans - font.pixelSize: 13 - font.weight: navVM.currentViewIndex === 0 ? Font.Bold : Font.Normal - color: navVM.currentViewIndex === 0 ? Theme.textPrimary : Theme.textSecondary - } - onClicked: navVM.navigateToLanding() - } - - Button { - text: qsTr("Дашборд") - flat: true - contentItem: Text { - text: parent.text - font.family: Theme.fontSans - font.pixelSize: 13 - font.weight: navVM.currentViewIndex === 1 ? Font.Bold : Font.Normal - color: navVM.currentViewIndex === 1 ? Theme.textPrimary : Theme.textSecondary - } - onClicked: navVM.navigateToDashboard() - } - - Button { - text: qsTr("Почати інтерв'ю") - contentItem: Text { - text: parent.text - font.family: Theme.fontSans - font.pixelSize: 13 - font.weight: Font.DemiBold - color: "#ffffff" - } - background: Rectangle { - radius: Theme.radiusSm - gradient: Gradient { - orientation: Gradient.Horizontal - GradientStop { position: 0.0; color: Theme.accentRose } - GradientStop { position: 1.0; color: Theme.accentIndigo } - } - } - onClicked: navVM.navigateToSetup() - } - } - } -} - diff --git a/apps/desktop/qml/components/ProgressRing.qml b/apps/desktop/qml/components/ProgressRing.qml new file mode 100644 index 0000000..c25c7ce --- /dev/null +++ b/apps/desktop/qml/components/ProgressRing.qml @@ -0,0 +1,60 @@ +import QtQuick +import QtQuick.Shapes +import DevDialogue.App + +// Circular progress indicator. `value` is 0..1; the arc starts at 12 o'clock +// and animates whenever the value changes. +Item { + id: root + + property real value: 0 + property real size: 40 + property real thickness: 4 + property color trackColor: Theme.zinc800 + property color progressColor: Theme.blue400 + property int animationDuration: 900 + + readonly property real clamped: Math.max(0, Math.min(1, value)) + property real shown: clamped + Behavior on shown { + NumberAnimation { duration: root.animationDuration; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring } + } + + implicitWidth: size + implicitHeight: size + + Shape { + anchors.fill: parent + layer.enabled: true + layer.samples: 4 + + ShapePath { + strokeColor: root.trackColor + strokeWidth: root.thickness + fillColor: "transparent" + PathAngleArc { + centerX: root.width / 2 + centerY: root.height / 2 + radiusX: (root.width - root.thickness) / 2 + radiusY: (root.height - root.thickness) / 2 + startAngle: 0 + sweepAngle: 360 + } + } + + ShapePath { + strokeColor: root.shown > 0.001 ? root.progressColor : "transparent" + strokeWidth: root.thickness + fillColor: "transparent" + capStyle: ShapePath.RoundCap + PathAngleArc { + centerX: root.width / 2 + centerY: root.height / 2 + radiusX: (root.width - root.thickness) / 2 + radiusY: (root.height - root.thickness) / 2 + startAngle: -90 + sweepAngle: 360 * root.shown + } + } + } +} diff --git a/apps/desktop/qml/components/PulseDot.qml b/apps/desktop/qml/components/PulseDot.qml new file mode 100644 index 0000000..0d5ee83 --- /dev/null +++ b/apps/desktop/qml/components/PulseDot.qml @@ -0,0 +1,38 @@ +import QtQuick +import DevDialogue.App + +// Status dot with a radar ping (web: animate-ping behind a solid dot). +Item { + id: root + + property color color: Theme.amber500 + property color pingColor: Theme.amber400 + property real size: 8 + property bool pinging: true + + implicitWidth: size + implicitHeight: size + + Rectangle { + id: ping + anchors.centerIn: parent + width: root.size + height: root.size + radius: width / 2 + color: root.pingColor + visible: root.pinging + + ParallelAnimation { + running: root.pinging && root.visible + loops: Animation.Infinite + NumberAnimation { target: ping; property: "scale"; from: 1.0; to: 2.0; duration: 1000; easing.type: Easing.OutCubic } + NumberAnimation { target: ping; property: "opacity"; from: 0.75; to: 0.0; duration: 1000; easing.type: Easing.OutCubic } + } + } + + Rectangle { + anchors.fill: parent + radius: width / 2 + color: root.color + } +} diff --git a/apps/desktop/qml/components/ScoreGauge.qml b/apps/desktop/qml/components/ScoreGauge.qml new file mode 100644 index 0000000..8f1bfd0 --- /dev/null +++ b/apps/desktop/qml/components/ScoreGauge.qml @@ -0,0 +1,84 @@ +import QtQuick +import DevDialogue.App + +// Overall score dial of the report screen: 144px disc with a zinc ring, the +// score counting up in the centre and a coloured arc filling to score/100. +// Colours follow the web thresholds (>= 80 emerald, >= 60 blue, else amber). +Item { + id: root + + property int score: 0 + property string suffix: qsTr("/ 100 points") + property bool animated: true + readonly property color scoreColor: Theme.scoreColor(score) + + // Number shown while counting up. + property real displayed: 0 + function restart() { + if (!animated) { + displayed = score + ring.value = score / 100 + return + } + countUp.stop() + displayed = 0 + ring.animationDuration = 0 + ring.value = 0 + ring.animationDuration = 1100 + ring.value = score / 100 + countUp.start() + } + onScoreChanged: restart() + Component.onCompleted: restart() + + implicitWidth: 144 + implicitHeight: 144 + + NumberAnimation { + id: countUp + target: root + property: "displayed" + from: 0 + to: root.score + duration: 1100 + easing.type: Easing.OutCubic + } + + Rectangle { + anchors.fill: parent + radius: width / 2 + color: Theme.zinc950 + } + + ProgressRing { + id: ring + anchors.fill: parent + size: root.width + thickness: 4 + trackColor: Theme.zinc800 + progressColor: root.scoreColor + } + + Column { + anchors.centerIn: parent + spacing: 0 + + AppText { + anchors.horizontalCenter: parent.horizontalCenter + text: Math.round(root.displayed) + color: root.scoreColor + font.pixelSize: Typography.xl5 + font.weight: Typography.black + font.letterSpacing: Typography.tracking(Typography.xl5, Typography.trackingTight) + } + AppText { + anchors.horizontalCenter: parent.horizontalCenter + text: root.suffix + color: Theme.textMuted + font.pixelSize: Typography.xs + font.weight: Typography.semibold + font.capitalization: Font.AllUppercase + font.letterSpacing: Typography.tracking(Typography.xs, Typography.trackingWider) + } + } +} diff --git a/apps/desktop/qml/components/SegmentedControl.qml b/apps/desktop/qml/components/SegmentedControl.qml new file mode 100644 index 0000000..1aeb594 --- /dev/null +++ b/apps/desktop/qml/components/SegmentedControl.qml @@ -0,0 +1,98 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import DevDialogue.App + +// Tab switcher used for Sign In / Sign Up, the settings tabs and the track +// tabs of the landing preview: dark tray, active segment filled blue. +// +// model: [{ value: "signin", label: qsTr("Sign In"), icon: "user" }, ...] +Rectangle { + id: control + + property var model: [] + property string currentValue + // Compact trays hug their content; regular ones stretch segments evenly. + property bool compact: false + signal activated(string value) + + implicitWidth: row.implicitWidth + padding * 2 + implicitHeight: row.implicitHeight + padding * 2 + readonly property int padding: compact ? 2 : 4 + + radius: compact ? Theme.radiusSm : Theme.radiusMd + color: Theme.alpha(Theme.zinc900, 0.9) + border.width: 1 + border.color: Theme.borderGlass + + RowLayout { + id: row + anchors.fill: parent + anchors.margins: control.padding + spacing: control.compact ? 4 : 0 + + Repeater { + model: control.model + + Rectangle { + id: segment + required property var modelData + readonly property bool active: modelData.value === control.currentValue + + Layout.fillWidth: !control.compact + Layout.preferredWidth: control.compact ? implicitWidth : 100 + implicitWidth: label.implicitWidth + (control.compact ? 24 : 16) + implicitHeight: control.compact ? 24 : 32 + radius: control.compact ? Theme.radiusXs : Theme.radiusSm + color: active ? Theme.primary : "transparent" + scale: tap.pressed ? 0.97 : 1.0 + activeFocusOnTab: true + + Behavior on color { ColorAnimation { duration: Theme.durationFast } } + Behavior on scale { + NumberAnimation { duration: Theme.durationFast; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.easeSpring } + } + + Keys.onReturnPressed: control.activated(modelData.value) + Keys.onSpacePressed: control.activated(modelData.value) + + RowLayout { + id: label + anchors.centerIn: parent + spacing: 8 + + Icon { + visible: segment.modelData.icon !== undefined && segment.modelData.icon !== "" + name: segment.modelData.icon !== undefined ? segment.modelData.icon : "" + size: 14 + color: labelText.color + } + AppText { + id: labelText + text: segment.modelData.label + font.pixelSize: Typography.xs + font.weight: control.compact ? Typography.medium : Typography.semibold + color: segment.active ? Theme.textOnAccent : (hover.hovered ? Theme.zinc200 : Theme.zinc400) + Behavior on color { ColorAnimation { duration: Theme.durationFast } } + } + } + + Rectangle { + anchors.fill: parent + anchors.margins: -2 + radius: parent.radius + 2 + color: "transparent" + border.width: 2 + border.color: Theme.focusRing + visible: segment.activeFocus + } + + HoverHandler { id: hover; cursorShape: Qt.PointingHandCursor } + TapHandler { + id: tap + onTapped: control.activated(segment.modelData.value) + } + } + } + } +} diff --git a/apps/desktop/qml/components/SelectBox.qml b/apps/desktop/qml/components/SelectBox.qml new file mode 100644 index 0000000..862a3aa --- /dev/null +++ b/apps/desktop/qml/components/SelectBox.qml @@ -0,0 +1,89 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Controls.Basic +import DevDialogue.App + +// Dark drop-down matching the