/*************************************************************************** | |
* Copyright (C) 2016 by Savoir-faire Linux * | |
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.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 3 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/>. * | |
**************************************************************************/ | |
#include "pch.h" | |
#include "SmartPanel.xaml.h" | |
using namespace Platform; | |
using namespace RingClientUWP; | |
using namespace RingClientUWP::Views; | |
using namespace RingClientUWP::ViewModel; | |
using namespace Windows::Media::Capture; | |
using namespace Windows::UI::Xaml; | |
using namespace Windows::Storage; | |
using namespace Windows::UI::Xaml::Media::Imaging; | |
using namespace Windows::UI::Xaml::Shapes; | |
using namespace Windows::UI::Xaml::Media; | |
using namespace Concurrency; | |
using namespace Windows::Foundation; | |
SmartPanel::SmartPanel() | |
{ | |
InitializeComponent(); | |
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; | |
_smartList_->ItemsSource = ContactsViewModel::instance->contactsList; | |
} | |
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) | |
{ | |
_shareMenuButton_->IsChecked = false; | |
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; | |
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
} | |
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) | |
{ | |
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
} | |
void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) | |
{ | |
_smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
_settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; | |
} | |
void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) | |
{ | |
_settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
_smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; | |
} | |
void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) | |
{ | |
if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { | |
_rowRingTxtBx_->Height = 40; | |
_selectedAccountAvatar_->Height = 80; | |
_selectedAccountAvatarColumn_->Width = 90; | |
_selectedAccountRow_->Height = 90; | |
} | |
else { | |
_rowRingTxtBx_->Height = 0; | |
_selectedAccountAvatar_->Height = 50; | |
_selectedAccountAvatarColumn_->Width = 60; | |
_selectedAccountRow_->Height = 60; | |
} | |
_selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; | |
_settingsTBtn_->IsChecked = false; | |
_accountsMenuButton_->IsChecked = false; | |
_shareMenuButton_->IsChecked = false; | |
} | |
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; | |
_accountsMenuButton_->IsChecked = false; | |
} | |
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
} | |
void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; | |
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; | |
} | |
void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
} | |
void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
} | |
void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); | |
cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; | |
cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); | |
create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) | |
{ | |
if (photo != nullptr) { | |
// maybe it would be possible to move some logics to the style sheet | |
auto brush = ref new ImageBrush(); | |
auto circle = ref new Ellipse(); | |
circle->Height = 80; // TODO : use some global constant when ready | |
circle->Width = 80; | |
auto path = photo->Path; | |
auto uri = ref new Windows::Foundation::Uri(path); | |
auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); | |
bitmapImage->UriSource = uri; | |
brush->ImageSource = bitmapImage; | |
circle->Fill = brush; | |
_avatarWebcamCaptureBtn_->Content = circle; | |
} | |
}); | |
} | |
void | |
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) | |
{ | |
auto listbox = safe_cast<ListBox^>(sender); | |
auto contact = safe_cast<Contact^>(listbox->SelectedItem); | |
ContactsViewModel::instance->selectedContact = contact; | |
} |