Add calendar QML components to the Plugin

This allows us to keep minimal API, since the calendar view and import
really belong together. Also makes it a lot easier to provide a separate
Calendar Plasmoid.
This commit is contained in:
Sebastian Kügler 2013-11-12 03:40:52 +01:00
parent 859e2ce352
commit 19db9c9663
8 changed files with 669 additions and 1 deletions

View File

@ -25,5 +25,5 @@ target_link_libraries(calendarplugin
)
install(TARGETS calendarplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/calendar)
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/calendar)
install(DIRECTORY qml/ DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/calendar)

View File

@ -0,0 +1,98 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import org.kde.plasma.calendar 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
Row {
id: calendarOperations
anchors {
left: parent.left
top: parent.top
right: parent.right
}
spacing: 4
Components.ToolButton {
id: monthright
flat: true;
text: "<";
width: height;
anchors.left: parent.left
anchors.rightMargin: 20
onClicked: {
monthCalendar.previousMonth()
}
}
Components.ToolButton {
id: month
anchors.left: monthright.right
anchors.right: monthYear.left
anchors.leftMargin: 20
Loader {
id: menuLoader
}
onClicked: {
if (menuLoader.source == "") {
menuLoader.source = "MonthMenu.qml"
} else {
//menuLoader.source = ""
}
menuLoader.item.open(0, height);
}
text: monthCalendar.monthName
}
Components.ToolButton {
id: monthYear
text: monthCalendar.year
anchors.leftMargin: 20
anchors.left: month.right
Components.ToolButton {
id: increase
text: "^"
width: 12
height: 12
anchors.left: monthYear.right
onClicked: monthCalendar.nextYear()
}
Components.ToolButton {
id: decrease
text: "v"
width: 12
height: 12
anchors.left: monthYear.right
anchors.top: increase.bottom
onClicked: monthCalendar.previousYear()
}
}
Components.ToolButton {
id: previous
flat: true;
text: ">";
width: height;
anchors.right: parent.right
onClicked: {
monthCalendar.nextMonth()
}
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import org.kde.plasma.calendar 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
DayStyle {
id: myRectangle
width: cellWidth
height: cellHeight
Components.Label {
id: label
anchors.centerIn: parent
//anchors.topMargin: 10
font.pixelSize: Math.max(theme.defaultFont.pixelSize, cellHeight / 3)
text: dayNumber
z: 99
font.bold: (containsEventItems)||(containsTodoItems) ? true: false
opacity: (isPreviousMonth || isNextMonth) ? 0.5: 1.0
}
MouseArea {
id: dateMouse
anchors.fill: parent
z: label.z + 1
hoverEnabled: true
onClicked: {
var rowNumber = Math.floor ( index / 7) ;
week = 1+monthCalendar.weeksModel[rowNumber];
date = dayNumber + "/" + monthNumber + "/" + yearNumber
calendarDays.selectedItem = myRectangle
}
}
}

View File

@ -0,0 +1,120 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import org.kde.plasma.calendar 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
id: dayStyle
//property int borderWidth: root.borderWidth`
property real borderOpacity: 0.2
property bool showtop: false
property bool showright: true
property bool showleft: false
property bool showbottom: true
Rectangle {
id: todayRect
x: 0
y: 0
z: -1
width: parent.width - (borderWidth)
height: parent.height - (borderWidth)
// anchors.fill: parent
opacity: calendarDays.selectedItem == dayStyle ? 0.8 : 0
Behavior on opacity { NumberAnimation {} }
color: theme.highlightColor
}
Rectangle {
id: highlightDate
anchors {
fill: todayRect
}
opacity: dateMouse.containsMouse ? 0.3 : 0
//visible: dateMouse.containsMouse
Behavior on opacity { NumberAnimation {} }
color: theme.viewBackgroundColor
border.color: isToday(dayNumber+"/"+monthNumber+"/"+yearNumber) ? theme.highlightColor : "transparent"
}
// Rectangle {
// id: frameTop
// height: borderWidth
// color: theme.textColor
// opacity: borderOpacity
// visible: showtop
//
// anchors {
// top: parent.top
// left: parent.left
// right: parent.right
// }
// }
Rectangle {
id: frameRight
width: borderWidth
color: theme.textColor
opacity: borderOpacity
visible: showright
anchors {
top: parent.top
bottom: parent.bottom
right: parent.right
}
}
Rectangle {
id: frameBottom
height: borderWidth
color: theme.textColor
opacity: borderOpacity
visible: showbottom
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
}
// Rectangle {
// id: frameLeft
// width: borderWidth
// color: theme.textColor
// opacity: borderOpacity
// visible: showleft
//
// anchors {
// top: parent.top
// left: parent.left
// bottom: parent.bottom
// }
// }
}

View File

@ -0,0 +1,123 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import org.kde.plasma.calendar 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
property real borderOpacity: 0.2
Rectangle {
id: frameTop
height: borderWidth
width: root.columns * root.cellWidth
color: theme.textColor
opacity: borderOpacity
// visible: showtop
anchors {
top: parent.top
left: calendarDays.left
//right: calendarDays.right
}
}
Rectangle {
id: frameLeft
width: borderWidth
height: root.cellHeight * root.columns
color: theme.textColor
opacity: borderOpacity
// visible: showtop
anchors {
right: calendarDays.left
top: calendarDays.top
//bottom: calendarDays.bottom
}
}
Rectangle {
id: frameRight
width: borderWidth
height: root.cellHeight
color: theme.textColor
opacity: borderOpacity
// visible: showtop
anchors {
right: frameTop.right
top: calendarDays.top
//bottom: calendarDays.bottom
}
}
Rectangle {
id: frameSecond
height: borderWidth
color: theme.textColor
opacity: borderOpacity
// // visible: /*showtop*/
y: cellHeight - borderWidth
anchors {
//top: parent.top
left: calendarDays.left
right: frameTop.right
}
}
Grid {
id: calendarDays
anchors.fill: parent
columns: monthCalendar.days
rows: 1 + monthCalendar.weeks
spacing: 0
property Item selectedItem
property bool containsEventItems: false // FIXME
property bool containsTodoItems: false // FIXME
Repeater {
id: days
model: monthCalendar.days
Item {
width: cellWidth
height: cellHeight
Components.Label {
text: Qt.formatDate(new Date(showDate.getFullYear(), showDate.getMonth(), index - firstDay +1), "ddd");
font.pixelSize: Math.max(theme.smallestFont.pixelSize, root.cellHeight / 6)
//font: theme.smallestFont
opacity: 0.2
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: borderWidth * 2
}
}
}
Repeater {
id: repeater
model: monthCalendar.daysModel
DayDelegate {}
}
}
}

View File

@ -0,0 +1,82 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.qtextracomponents 2.0 as QtExtras
PlasmaComponents.Menu {
id: testMenu
PlasmaComponents.MenuItem {
text: "January"
onClicked: monthCalendar.startDate="2013-01-01"
}
PlasmaComponents.MenuItem {
text: "February"
onClicked: monthCalendar.startDate="2013-02-01"
}
PlasmaComponents.MenuItem {
text: "March"
onClicked: monthCalendar.startDate="2013-03-01"
}
PlasmaComponents.MenuItem {
text: "April"
onClicked: monthCalendar.startDate="2013-04-01"
}
PlasmaComponents.MenuItem {
text: "May"
onClicked: monthCalendar.startDate="2013-05-01"
}
PlasmaComponents.MenuItem {
text: "June"
onClicked: monthCalendar.startDate="2013-06-01"
}
PlasmaComponents.MenuItem {
text: "July"
onClicked: monthCalendar.startDate="2013-07-01"
}
PlasmaComponents.MenuItem {
text: "August"
onClicked: monthCalendar.startDate="2013-08-01"
}
PlasmaComponents.MenuItem {
text: "September"
onClicked: monthCalendar.startDate="2013-09-01"
}
PlasmaComponents.MenuItem {
text: "October"
onClicked: monthCalendar.startDate="2013-10-01"
}
PlasmaComponents.MenuItem {
text: "November"
onClicked: monthCalendar.startDate="2013-11-01"
}
PlasmaComponents.MenuItem {
text: "December"
onClicked: monthCalendar.startDate="2013-12-01"
}
Component.onCompleted:{
print("TestMenu.qml served .. opening");
}
}

View File

@ -0,0 +1,189 @@
/*
* Copyright 2013 Heena Mahour <heena393@gmail.com>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import org.kde.plasma.calendar 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
id: root
width: parent.width
height: parent.height
property string date ;
property date showDate: new Date()
property alias calendarGrid: calendarGrid
property int mWidth: theme.mSize(theme.defaultFont).width
property int mHeight: theme.mSize(theme.defaultFont).height
property int borderWidth: 1
property int columns: monthCalendar.days
property int rows: 1 + monthCalendar.weeks
property int cellWidth: prefCellWidth()
property int cellHeight: prefCellHeight()
property int miniumWidth: implicitWidth
property int miniumHeight: implicitHeight
property int implicitWidth: theme.mSize(theme.defaultFont).width * 6 * 8
property int implicitHeight: theme.mSize(theme.defaultFont).height * 2 * 9
//property int cellFontPixelSize: theme.defaultFont.pixelSize
property Item selectedItem
property int week;
property int firstDay: new Date(showDate.getFullYear(), showDate.getMonth(), 1).getDay()
anchors.margins: theme.largeSpacing * 3
function prefCellWidth() {
return Math.min(
Math.max(
mWidth * 4,
calendarGrid.width / (root.columns)
),
mWidth * 100
)
}
function prefCellHeight() {
return Math.min(
Math.max(
mHeight * 1.5,
calendarGrid.height / (root.rows + 1)
),
mHeight * 40
)
}
function isToday(date) {
if (date == Qt.formatDateTime(new Date(), "d/M/yyyy")) {
return true;
}
else return false;
}
function isTodayMonth() {
return Qt.formatDateTime(new Date(), "yyyy-MM-dd")
}
function eventDate(yearNumber,monthNumber,dayNumber) {
var d = new Date(yearNumber, monthNumber-1, dayNumber);
return Qt.formatDate(d, "dddd dd MMM yyyy");
}
//Rectangle { anchors.fill: monthCalendar; color: "green"; opacity: 0.3 }
PlasmaExtras.Heading {
id: monthHeading
anchors {
top: parent.top
left: calendarGrid.left
right: parent.right
leftMargin: -borderWidth
}
level: 1
opacity: 0.8
text: monthCalendar.monthName
}
Calendar {
id: monthCalendar
days: 7
weeks: 6
startDay: 1
startDate: "2013-08-01"
onStartDateChanged: {
//monthHeading.text = monthName
month.text = monthName
monthYear.text = year
}
}
// CalendarToolbar {
//
// }
//Rectangle { anchors.fill: calendarGrid; color: "orange"; opacity: 0.3; }
DaysCalendar {
id: calendarGrid
anchors {
top: monthHeading.bottom
left: parent.left
right: parent.right
bottom: calendarToolbar.top
margins: theme.largeSpacing
bottomMargin: theme.largeSpacing * 3
topMargin: - (theme.largeSpacing / 2)
}
}
Item {
id: calendarToolbar
anchors {
left: parent.left
right: parent.right
bottomMargin: 20
bottom: parent.bottom
}
Components.ToolButton {
id: currentDate
iconSource: "view-pim-calendar"
width: height
onClicked: {
monthCalendar.startDate = isTodayMonth();
}
PlasmaCore.ToolTip {
id: tool
target: currentDate
mainText: "Select Today"
}
anchors {
left: parent.left
}
}
Components.TextField {
id: dateField
text: date == "" ? Qt.formatDateTime ( new Date(), "d/M/yyyy" ): date
width: calendarOperations.width/3
anchors {
leftMargin: 20
rightMargin: 30
left: currentDate.right
right: weekField.left
}
}
Components.TextField {
id: weekField
text: week == 0 ? monthCalendar.currentWeek(): week
width: calendarOperations.width/10
anchors {
right: parent.right
}
}
}
}

View File

@ -0,0 +1,4 @@
module org.kde.plasma.calendar
plugin calendarplugin
MonthView 2.0 MonthView.qml