diff options
Diffstat (limited to 'src/libcommuni/examples/quick')
| -rw-r--r-- | src/libcommuni/examples/quick/main.cpp | 20 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/BufferListView.qml | 92 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/ChatPage.qml | 111 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/ConnectPage.qml | 160 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/MessageFormatter.qml | 215 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/TextBrowser.qml | 47 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/TextEntry.qml | 77 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/TopicLabel.qml | 48 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/UserListView.qml | 71 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/qml/main.qml | 80 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/quick.pro | 28 | ||||
| -rw-r--r-- | src/libcommuni/examples/quick/quick.qrc | 13 |
12 files changed, 962 insertions, 0 deletions
diff --git a/src/libcommuni/examples/quick/main.cpp b/src/libcommuni/examples/quick/main.cpp new file mode 100644 index 0000000..c503b98 --- /dev/null +++ b/src/libcommuni/examples/quick/main.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + app.setOrganizationName("Commmuni"); + app.setApplicationName("QtQuick Example"); + QQmlApplicationEngine engine(QUrl("qrc:/main.qml")); + return app.exec(); +} diff --git a/src/libcommuni/examples/quick/qml/BufferListView.qml b/src/libcommuni/examples/quick/qml/BufferListView.qml new file mode 100644 index 0000000..3d277b6 --- /dev/null +++ b/src/libcommuni/examples/quick/qml/BufferListView.qml @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import Communi 3.0 + +Rectangle { + id: background + + property alias bufferModel: listView.model + property IrcBuffer currentBuffer + + signal closed(IrcBuffer buffer) + + color: "#edf3fe" + + Rectangle { + id: frame + anchors.fill: parent + anchors.topMargin: -1 + color: "transparent" + border.color: "#aaa" + } + + Menu { + id: menu + MenuItem { + text: qsTr("Close") + shortcut: qsTr("Ctrl+W") + enabled: !!currentBuffer + onTriggered: closed(currentBuffer) + } + } + + ScrollView { + id: scrollView + + anchors.fill: parent + anchors.topMargin: -1 + + ListView { + id: listView + + delegate: Rectangle { + property bool first: index === 0 + property bool current: model.buffer === currentBuffer + anchors.left: parent ? parent.left : undefined + anchors.right: parent ? parent.right : undefined + anchors.margins: 1 + height: Math.max(21, label.implicitHeight + 5) + color: first ? "#ddd" : current ? "#b5d5ff" : "transparent" + Rectangle { + visible: first + width: parent.width + height: 1 + anchors.bottom: parent.bottom + anchors.fill: parent + anchors.leftMargin: -1 + anchors.rightMargin: -1 + color: "transparent" + border.color: "#aaa" + } + Label { + id: label + text: model.title + font.bold: first + anchors.margins: 2 + anchors.leftMargin: 6 + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onPressed: { + currentBuffer = model.buffer + if (mouse.button === Qt.RightButton) + menu.popup() + } + } + } + } + } +} diff --git a/src/libcommuni/examples/quick/qml/ChatPage.qml b/src/libcommuni/examples/quick/qml/ChatPage.qml new file mode 100644 index 0000000..474b950 --- /dev/null +++ b/src/libcommuni/examples/quick/qml/ChatPage.qml @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Styles 1.0 +import Communi 3.0 + +Item { + id: page + + property IrcBuffer serverBuffer + property alias bufferModel: bufferListView.bufferModel + property alias currentBuffer: bufferListView.currentBuffer + property IrcChannel currentChannel: currentBuffer ? currentBuffer.toChannel() : null + + Connections { + target: bufferModel + onAdded: currentBuffer = buffer + onAboutToBeRemoved: { + var idx = bufferModel.indexOf(buffer) + currentBuffer = bufferModel.get(idx + 1) || bufferModel.get(Math.max(0, idx - 1)) + } + } + + SplitView { + anchors.fill: parent + + handleDelegate: Item { } + + BufferListView { + id: bufferListView + width: page.width / 6 + onClosed: { + if (buffer === serverBuffer) { + bufferModel.quit() + } else { + if (buffer.channel) + buffer.part(qsTr("Communi %1 QtQuick example").arg(irc.version())) + bufferModel.remove(buffer) + } + } + } + + Column { + Layout.fillWidth: true + + TopicLabel { + id: topicLabel + width: parent.width + visible: currentChannel + channel: currentChannel + } + + SplitView { + width: parent.width + height: parent.height - (currentChannel ? topicLabel.height : 0) - textEntry.height + + handleDelegate: Item { } + + Item { + id: stack + + width: 1; height: 1 + Layout.fillWidth: true + Layout.fillHeight: true + + Repeater { + anchors.fill: parent + model: bufferModel + delegate: TextBrowser { + anchors.fill: parent + buffer: model.buffer + visible: buffer == currentBuffer + } + } + } + + UserListView { + width: page.width / 6 + visible: currentChannel + channel: currentChannel + onQueried: currentBuffer = currentBuffer.model.add(user.name) + } + } + + TextEntry { + id: textEntry + width: parent.width + buffer: currentBuffer + enabled: currentBuffer + onMessageSent: currentBuffer.receiveMessage(message) + + Connections { + target: page + onCurrentBufferChanged: { + if (page.visible && currentBuffer) + textEntry.forceActiveFocus() + } + } + } + } + } +} diff --git a/src/libcommuni/examples/quick/qml/ConnectPage.qml b/src/libcommuni/examples/quick/qml/ConnectPage.qml new file mode 100644 index 0000000..8a7c296 --- /dev/null +++ b/src/libcommuni/examples/quick/qml/ConnectPage.qml @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 +import Qt.labs.settings 1.0 +import Communi 3.0 + +Item { + id: page + + property string host: hostField.text || hostField.placeholderText + property int port: portField.value + property bool secure: secureField.checked + property bool sasl: saslField.checked + property string nickName: nickNameField.text || nickNameField.placeholderText + property string realName: realNameField.text || realNameField.placeholderText + property string userName: userNameField.text || userNameField.placeholderText + property string password: passwordField.text + property string channel: channelField.text || channelField.placeholderText + + Settings { + id: settings + property alias host: hostField.text + property alias port: portField.value + property alias secure: secureField.checked + property alias sasl: saslField.checked + property alias nickName: nickNameField.text + property alias realName: realNameField.text + property alias userName: userNameField.text + property alias password: passwordField.text + property alias channel: channelField.text + } + + signal accepted() + signal rejected() + + implicitWidth: grid.implicitWidth + row.implicitWidth + implicitHeight: grid.implicitHeight + row.implicitHeight + 48 + + GridLayout { + id: grid + + width: page.width * 2 / 3 + anchors.centerIn: parent + anchors.verticalCenterOffset: -row.height + 12 + + columns: 2 + rowSpacing: 12 + columnSpacing: 12 + + Label { text: qsTr("Host:") } + TextField { + id: hostField + focus: true + Layout.fillWidth: true + placeholderText: "irc.freenode.net" + } + + Label { text: qsTr("Port:") } + RowLayout { + SpinBox { + id: portField + value: 6667 + minimumValue: 1024 + maximumValue: 65535 + Layout.fillWidth: true + } + CheckBox { + id: secureField + text: qsTr("SSL") + } + CheckBox { + id: saslField + text: qsTr("SASL") + } + } + + Label { text: qsTr("Nick name:") } + TextField { + id: nickNameField + Layout.fillWidth: true + placeholderText: "Quick" + Math.round(Math.random() * 9999) + } + + Label { text: qsTr("Real name:") } + TextField { + id: realNameField + Layout.fillWidth: true + placeholderText: qsTr("Communi %1 QtQuick example").arg(irc.version()) + } + + Label { text: qsTr("User name:") } + TextField { + id: userNameField + Layout.fillWidth: true + placeholderText: "communi" + } + + Label { text: qsTr("Password:") } + TextField { + id: passwordField + echoMode: TextInput.Password + Layout.fillWidth: true + } + + Label { text: qsTr("Channel:") } + TextField { + id: channelField + Layout.fillWidth: true + placeholderText: "#communi" + } + } + + Keys.onReturnPressed: { + if (okButton.enabled) + page.accepted() + } + + Keys.onEnterPressed: { + if (okButton.enabled) + page.accepted() + } + + Keys.onEscapePressed: { + if (cancelButton.enabled) + page.rejected() + } + + RowLayout { + id: row + + anchors.margins: 12 + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + + Item { Layout.fillWidth: true } + + Button { + id: okButton + text: qsTr("Ok") + enabled: page.visible + onClicked: page.accepted() + } + + Button { + id: cancelButton + text: qsTr("Cancel") + onClicked: page.rejected() + } + } +} diff --git a/src/libcommuni/examples/quick/qml/MessageFormatter.qml b/src/libcommuni/examples/quick/qml/MessageFormatter.qml new file mode 100644 index 0000000..754ca1c --- /dev/null +++ b/src/libcommuni/examples/quick/qml/MessageFormatter.qml @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import Communi 3.0 + +QtObject { + id: root + + property IrcTextFormat textFormat: IrcTextFormat { + id: textFormat + + palette.gray: "#606060" + palette.lightGray: "#808080" + + // http://ethanschoonover.com/solarized + palette.blue: "#268bd2" + palette.green: "#859900" + palette.red: "#dc322f" + palette.brown: "#cb4b16" + palette.purple: "#6c71c4" + palette.orange: "#cb4b16" + palette.yellow: "#b58900" + palette.lightGreen: "#859900" + palette.cyan: "#2aa198" + palette.lightCyan: "#2aa198" + palette.lightBlue: "#268bd2" + palette.pink: "#6c71c4" + } + + function formatMessage(message) { + var formatted + switch (message.type) { + case IrcMessage.Invite: formatted = formatInviteMessage(message); break + case IrcMessage.Join: formatted = formatJoinMessage(message); break + case IrcMessage.Kick: formatted = formatKickMessage(message); break + case IrcMessage.Mode: formatted = formatModeMessage(message); break + case IrcMessage.Names: formatted = formatNamesMessage(message); break + case IrcMessage.Nick: formatted = formatNickMessage(message); break + case IrcMessage.Notice: formatted = formatNoticeMessage(message); break + case IrcMessage.Numeric: formatted = formatNumericMessage(message); break + case IrcMessage.Part: formatted = formatPartMessage(message); break + case IrcMessage.Private: formatted = formatPrivateMessage(message); break + case IrcMessage.Quit: formatted = formatQuitMessage(message); break + case IrcMessage.Topic: formatted = formatTopicMessage(message); break + } + return formatText(formatted, message.timeStamp) + } + + function formatText(text, timeStamp) { + if (text) { + switch (text[0]) { + case '!': text = qsTr("<font color='gray'>%1</font>").arg(text); break; + case '[': text = qsTr("<font color='brown'>%1</font>").arg(text); break; + case '*': text = qsTr("<font color='darkmagenta'>%1</font>").arg(text); break; + case '?': text = qsTr("<font color='brown'>%1</font>").arg(text); break; + default: break; + } + + return qsTr("<font color='gray'>[%1]</font> %2").arg(Qt.formatTime(timeStamp, "hh:mm:ss")).arg(text) + } + } + + function formatInviteMessage(message) { + var sender = formatName(message.nick) + return qsTr("! %1 invited to %3").arg(sender).arg(message.channel) + } + + function formatJoinMessage(message) { + var sender = formatName(message.nick) + return qsTr("! %1 joined %2").arg(sender).arg(message.channel) + } + + function formatKickMessage(message) { + var sender = formatName(message.nick) + var user = formatName(message.user) + if (message.reason.length) + return qsTr("! %1 kicked %2 (%3)").arg(sender).arg(user).arg(message.reason) + return qsTr("! %1 kicked %2").arg(sender).arg(user) + } + + function formatModeMessage(message) { + var sender = formatName(message.nick) + if (message.reply) + return qsTr("! %1 mode is %2 %3").arg(message.target).arg(message.mode).arg(message.argument) + return qsTr("! %1 sets mode %2 %3").arg(sender).arg(message.mode).arg(message.argument) + } + + function formatNamesMessage(message) { + return qsTr("! %1 has %2 users").arg(message.channel).arg(message.names.length) + } + + function formatNickMessage(message) { + var sender = formatName(message.nick) + var nick = formatName(message.newNick) + return qsTr("! %1 changed nick to %2").arg(sender).arg(nick) + } + + function formatNoticeMessage(message) { + var sender = formatName(message.nick) + var content = formatHtml(message.content) + return qsTr("[%1] %2").arg(sender).arg(content) + } + + function formatNumericMessage(message) { + switch (message.code) { + case Irc.RPL_TOPIC: + case Irc.RPL_TOPICWHOTIME: + case Irc.RPL_CHANNEL_URL: + case Irc.RPL_NAMREPLY: + case Irc.RPL_ENDOFNAMES: + return // ignore + default: + return qsTr("[%1] %2").arg(message.code).arg(message.parameters.slice(1).join(" ")) + } + } + + function formatPartMessage(message) { + var sender = formatName(message.nick) + if (message.reason.length) + return qsTr("! %1 parted %2 (%3)").arg(sender).arg(message.channel).arg(formatHtml(message.reason)) + return qsTr("! %1 parted %2").arg(sender).arg(message.channel) + } + + function formatPrivateMessage(message) { + var sender = formatName(message.nick) + var content = formatHtml(message.content) + if (message.action) + return qsTr("* %1 %2").arg(sender).arg(content) + if (message.request) + return qsTr("! %1 requested %2").arg(sender).arg(content.split(" ")[0].toLowerCase()) + return qsTr("<%1> %2").arg(sender).arg(content) + } + + function formatQuitMessage(message) { + var sender = formatName(message.nick) + if (message.reason.length) + return qsTr("! %1 has quit (%2)").arg(sender).arg(formatHtml(message.reason)) + return qsTr("! %1 has quit").arg(sender) + } + + function formatTopicMessage(message) { + var sender = formatName(message.nick) + var topic = formatHtml(message.topic) + var channel = message.channel + if (message.reply) + return qsTr("! %1 topic is \"%2\"").arg(channel).arg(topic) + return qsTr("! %1 sets topic \"%2\" on %3").arg(sender).arg(topic).arg(channel) + } + + function formatHtml(message) { + return textFormat.toHtml(message) + } + + function formatName(name) { + var color = hslToRgb((hashCode(name) % 359)/359, 0.5, 0.25) + var r = ("0" + Math.round(Math.abs(color[0])).toString(16)).substr(-2) + var g = ("0" + Math.round(Math.abs(color[1])).toString(16)).substr(-2) + var b = ("0" + Math.round(Math.abs(color[2])).toString(16)).substr(-2) + return qsTr("<b><font color='#%1'>%2</font></b>").arg(r+g+b).arg(name); + } + + function hashCode(str) { + var hash = 0; + if (str.length == 0) return hash; + for (var i = 0; i < str.length; i++) { + var chr = str.charCodeAt(i); + hash = ((hash<<5)-hash)+chr; + hash = hash & hash; // Convert to 32bit integer + } + return hash; + } + + /** + * Converts an HSL color value to RGB. Conversion formula + * adapted from http://en.wikipedia.org/wiki/HSL_color_space. + * Assumes h, s, and l are contained in the set [0, 1] and + * returns r, g, and b in the set [0, 255]. + * + * @param Number h The hue + * @param Number s The saturation + * @param Number l The lightness + * @return Array The RGB representation + */ + function hslToRgb(h, s, l){ + var r, g, b; + + function hue2rgb(p, q, t){ + if(t < 0) t += 1; + if(t > 1) t -= 1; + if(t < 1/6) return p + (q - p) * 6 * t; + if(t < 1/2) return q; + if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; + return p; + } + + if(s == 0){ + r = g = b = l; // achromatic + }else{ + var q = l < 0.5 ? l * (1 + s) : l + s - l * s; + var p = 2 * l - q; + r = hue2rgb(p, q, h + 1/3); + g = hue2rgb(p, q, h); + b = hue2rgb(p, q, h - 1/3); + } + + return [r * 255, g * 255, b * 255]; + } +} diff --git a/src/libcommuni/examples/quick/qml/TextBrowser.qml b/src/libcommuni/examples/quick/qml/TextBrowser.qml new file mode 100644 index 0000000..fb013bc --- /dev/null +++ b/src/libcommuni/examples/quick/qml/TextBrowser.qml @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import Communi 3.0 + +Item { + id: background + + property IrcBuffer buffer + + implicitWidth: textArea.implicitWidth + implicitHeight: textArea.implicitHeight + + MessageFormatter { + id: formatter + } + + Connections { + target: buffer + onMessageReceived: { + var line = formatter.formatMessage(message) + if (line) + textArea.append(line) + } + } + + TextArea { + id: textArea + + anchors.fill: parent + anchors.topMargin: -1 + anchors.leftMargin: -1 + anchors.bottomMargin: -1 + + readOnly: true + textFormat: Qt.RichText + frameVisible: false + } +} diff --git a/src/libcommuni/examples/quick/qml/TextEntry.qml b/src/libcommuni/examples/quick/qml/TextEntry.qml new file mode 100644 index 0000000..4201e86 --- /dev/null +++ b/src/libcommuni/examples/quick/qml/TextEntry.qml @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Styles 1.0 +import Communi 3.1 + +TextField { + id: textField + + property alias buffer: completer.buffer + + signal messageSent(IrcMessage message) + + focus: true + placeholderText: qsTr("...") + + Keys.onTabPressed: completer.complete(text, cursorPosition) + + IrcCompleter { + id: completer + + onCompleted: { + textField.text = text + textField.cursorPosition = cursor + } + + parser: IrcCommandParser { + id: parser + + tolerant: true + triggers: ["/"] + channels: buffer ? buffer.model.channels : [] + target: buffer ? buffer.title : "" + + Component.onCompleted: { + parser.addCommand(IrcCommand.Join, "JOIN <#channel> (<key>)") + parser.addCommand(IrcCommand.CtcpAction, "ME [target] <message...>") + parser.addCommand(IrcCommand.Nick, "NICK <nick>") + parser.addCommand(IrcCommand.Part, "PART (<#channel>) (<message...>)") + } + } + } + + style: TextFieldStyle { + background: Rectangle { + color: palette.base + Rectangle { + color: "transparent" + anchors.fill: parent + anchors.leftMargin: -1 + border.color: "#aaa" + } + } + } + + onAccepted: { + var cmd = parser.parse(text) + if (cmd) { + buffer.connection.sendCommand(cmd) + if (cmd.type === IrcCommand.Message + || cmd.type === IrcCommand.CtcpAction + || cmd.type === IrcCommand.Notice) { + var msg = cmd.toMessage(buffer.connection.nickName, buffer.connection) + textField.messageSent(msg) + } + textField.text = "" + } + } +} diff --git a/src/libcommuni/examples/quick/qml/TopicLabel.qml b/src/libcommuni/examples/quick/qml/TopicLabel.qml new file mode 100644 index 0000000..4009304 --- /dev/null +++ b/src/libcommuni/examples/quick/qml/TopicLabel.qml @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import Communi 3.0 + +Rectangle { + id: background + + property IrcChannel channel + + color: "#ddd" + height: Math.max(20, label.implicitHeight + 4) + + IrcTextFormat { + id: textFormat + } + + Label { + id: label + + anchors.margins: 2 + anchors.leftMargin: 4 + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + + wrapMode: Text.Wrap + text: channel && channel.topic ? textFormat.toHtml(channel.topic) : "-" + } + + Rectangle { + id: frame + + color: "transparent" + anchors.fill: parent + anchors.topMargin: -1 + anchors.leftMargin: -1 + border.color: "#aaa" + } +} diff --git a/src/libcommuni/examples/quick/qml/UserListView.qml b/src/libcommuni/examples/quick/qml/UserListView.qml new file mode 100644 index 0000000..6daf06b --- /dev/null +++ b/src/libcommuni/examples/quick/qml/UserListView.qml @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import Communi 3.0 + +Rectangle { + id: background + + property IrcChannel channel + + signal queried(IrcUser user) + + color: "#edf3fe" + + Rectangle { + id: frame + anchors.fill: parent + color: "transparent" + border.color: "#aaa" + anchors.topMargin: -1 + anchors.leftMargin: -1 + anchors.bottomMargin: -1 + } + + ScrollView { + id: scrollView + + anchors.fill: parent + anchors.topMargin: -1 + anchors.bottomMargin: -1 + + ListView { + id: listView + + model: IrcUserModel { + id: userModel + sortMethod: Irc.SortByTitle + channel: background.channel + onChannelChanged: listView.currentIndex = -1 + } + + delegate: Rectangle { + width: parent.width + height: Math.max(20, label.implicitHeight + 4) + color: ListView.isCurrentItem ? "#b5d5ff" : "transparent" + Label { + id: label + text: model.title + anchors.margins: 2 + anchors.leftMargin: 6 + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + } + MouseArea { + anchors.fill: parent + onPressed: listView.currentIndex = index + onDoubleClicked: queried(model.user) + } + } + } + } +} diff --git a/src/libcommuni/examples/quick/qml/main.qml b/src/libcommuni/examples/quick/qml/main.qml new file mode 100644 index 0000000..8c431ad --- /dev/null +++ b/src/libcommuni/examples/quick/qml/main.qml @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008-2014 The Communi Project + * + * This example is free, and not covered by the BSD license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. + */ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import Communi 3.0 + +ApplicationWindow { + id: window + + visible: true + title: qsTr("Communi %1 QtQuick example").arg(irc.version()) + + width: 800 + height: 480 + + minimumWidth: connectPage.implicitWidth + minimumHeight: connectPage.implicitHeight + + color: Qt.darker(palette.base, 1.06) + + SystemPalette { id: palette } + + Irc { id: irc } + IrcCommand { id: cmd } + + ConnectPage { + id: connectPage + anchors.fill: parent + visible: !connection.active + onAccepted: { + chatPage.currentBuffer = serverBuffer + connection.sendCommand(cmd.createJoin(channel)) + connection.open() + } + onRejected: Qt.quit() + } + + ChatPage { + id: chatPage + anchors.fill: parent + visible: connection.active + bufferModel: IrcBufferModel { + id: bufferModel + sortMethod: Irc.SortByTitle + connection: IrcConnection { + id: connection + host: connectPage.host + port: connectPage.port + secure: connectPage.secure + saslMechanism: connectPage.sasl ? supportedSaslMechanisms[0] : "" + nickName: connectPage.nickName + realName: connectPage.realName + userName: connectPage.userName + password: connectPage.password + } + onMessageIgnored: serverBuffer.receiveMessage(message) + function quit() { + bufferModel.clear() + connection.quit(qsTr("Communi %1 QtQuick example").arg(irc.version())) + connection.close() + } + } + serverBuffer: IrcBuffer { + id: serverBuffer + sticky: true + persistent: true + name: connection.displayName + Component.onCompleted: bufferModel.add(serverBuffer) + } + } + + Component.onDestruction: bufferModel.quit() +} diff --git a/src/libcommuni/examples/quick/quick.pro b/src/libcommuni/examples/quick/quick.pro new file mode 100644 index 0000000..10690af --- /dev/null +++ b/src/libcommuni/examples/quick/quick.pro @@ -0,0 +1,28 @@ +###################################################################### +# Communi +###################################################################### + +TEMPLATE = app +TARGET = quick +DEPENDPATH += . +INCLUDEPATH += . +QT += network quick + +lessThan(QT_MAJOR_VERSION, 5)|lessThan(QT_MINOR_VERSION, 2) { + error(The Qt Quick 2 based example requires Qt 5.2 or newer but Qt $$[QT_VERSION] was detected.) +} + +# Input +SOURCES += main.cpp +RESOURCES += quick.qrc +OTHER_FILES += qml/main.qml +OTHER_FILES += qml/BufferListView.qml +OTHER_FILES += qml/ChatPage.qml +OTHER_FILES += qml/ConnectPage.qml +OTHER_FILES += qml/MessageFormatter.qml +OTHER_FILES += qml/TextBrowser.qml +OTHER_FILES += qml/TextEntry.qml +OTHER_FILES += qml/TopicLabel.qml +OTHER_FILES += qml/UserListView.qml + +include(../examples.pri) diff --git a/src/libcommuni/examples/quick/quick.qrc b/src/libcommuni/examples/quick/quick.qrc new file mode 100644 index 0000000..aba83b9 --- /dev/null +++ b/src/libcommuni/examples/quick/quick.qrc @@ -0,0 +1,13 @@ +<RCC> + <qresource prefix="/"> + <file alias="main.qml">qml/main.qml</file> + <file alias="BufferListView.qml">qml/BufferListView.qml</file> + <file alias="ChatPage.qml">qml/ChatPage.qml</file> + <file alias="ConnectPage.qml">qml/ConnectPage.qml</file> + <file alias="MessageFormatter.qml">qml/MessageFormatter.qml</file> + <file alias="TextBrowser.qml">qml/TextBrowser.qml</file> + <file alias="TextEntry.qml">qml/TextEntry.qml</file> + <file alias="TopicLabel.qml">qml/TopicLabel.qml</file> + <file alias="UserListView.qml">qml/UserListView.qml</file> + </qresource> +</RCC> |
