// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// iPhone required adjusting the dynamic type (font size etc.), settings had to be modified to run at the lowest font size
// Maybe implement this later, for now Adjustment within Qt default font will suffice
// http://stackoverflow.com/questions/2528385/is-there-anyway-to-set-values-in-the-settings-bundle-from-within-the-app
// http://stackoverflow.com/questions/8370913/iphone-changing-app-settings-programmatically
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/
// http://stackoverflow.com/questions/7252020/iphone-application-preferences
// http://stackoverflow.com/questions/20998894/accessing-xamarin-ios-settings-bundle
// http://useyourloaf.com/blog/adding-a-settings-bundle-to-an-iphone-app/
// https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html
// https://forum.qt.io/topic/54371/solved-working-with-ios-settings-bundle-preferences/11
// https://wiki.qt.io/IOS_Settings_Bundle
// http://stackoverflow.com/questions/30293786/add-settings-entry-for-ios-app-using-qt-5-4
// http://stackoverflow.com/questions/30350309/registering-ios-default-user-preferences-in-qt
// http://stackoverflow.com/questions/9181544/setting-bundle-default-value-wont-set
// http://stackoverflow.com/questions/38316591/how-to-test-dynamic-type-larger-font-sizes-in-ios-simulator/38316592#38316592
// https://bugreports.qt.io/browse/QTBUG-37563
// http://mokagio.github.io/tech-journal/2015/03/03/xcode-launch-arguments.html
// http://stackoverflow.com/questions/5714372/how-to-empty-caches-and-clean-all-targets-xcode-4
// http://stackoverflow.com/questions/16451136/how-to-use-multi-value-title-and-value-from-settings-bundle
// http://stackoverflow.com/questions/25413517/uictcontentsizecategory-in-swift
// http://stackoverflow.com/questions/13437584/settings-bundle-not-syncing-up-with-nsuserdefaults
// http://stackoverflow.com/questions/8707082/set-a-default-font-for-whole-ios-app
// http://stackoverflow.com/questions/22085059/what-method-do-you-call-to-get-the-users-preferred-text-size
// http://useyourloaf.com/blog/supporting-dynamic-type/
// http://stackoverflow.com/questions/9499894/how-to-read-string-from-nsuserdefaults
// http://stackoverflow.com/questions/20510094/how-to-use-a-custom-font-with-dynamic-text-sizes-in-ios7
// https://gist.github.com/klaas/750f489e2390389ab812
// http://samwize.com/2016/05/05/dynamic-type-changes-text-sizes-and-fonts-automatically/
// http://useyourloaf.com/blog/scaling-dynamic-type-with-font-descriptors/
// http://stackoverflow.com/questions/8707082/set-a-default-font-for-whole-ios-app
// http://tirania.org/monomac/archive/2013/Sep-25.html
// https://developer.apple.com/reference/uikit/uiapplication/1658987-content_size_category_constants?language=objc
// http://www.priyaontech.com/2014/04/supporting-dynamic-text-in-your-ios-apps/
// http://stackoverflow.com/questions/20464814/changing-dpi-scaling-size-of-display-make-qt-applications-font-size-get-rendere
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Native iOS method to set the default text size settings to minimum to fit well into the iPhone screen
#import "ios/iosdefaulttextsize.h"

#if defined(Q_OS_IOS)
    #import <UIKit/UIKit.h>
#endif

iosDefaultTextSize::iosDefaultTextSize(QObject *parent) : QObject(parent)
{
}

// Method to set the default text size in iOS
void iosDefaultTextSize::setDefaultTextSize()
{
    #if defined(Q_OS_IOS)

        // Get the application defaults
        // http://stackoverflow.com/questions/38316591/how-to-test-dynamic-type-larger-font-sizes-in-ios-simulator/38316592#38316592
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        // Set the new settings and save*
        [defaults setObject:@"UICTContentSizeCategoryXS" forKey:@"UIPreferredContentSizeCategoryName"];
        [defaults synchronize];

    #endif
}

// Method to determine if we are on an iPad or an iPhone
// http://stackoverflow.com/questions/2862140/best-way-to-programmatically-detect-ipad-iphone-hardware
bool iosDefaultTextSize::isIPhone()
{
    #if defined(Q_OS_IOS)

        if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            return false;
        }
        else
        {
            return true;
        }

    #endif
}
