VMConfigDisplayViewController.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // Copyright © 2019 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMConfigDisplayViewController.h"
  17. #import "UTMQemuConfiguration.h"
  18. #import "UTMQemuConfiguration+Constants.h"
  19. #import "UTMQemuConfiguration+Display.h"
  20. @interface VMConfigDisplayViewController ()
  21. @end
  22. @implementation VMConfigDisplayViewController
  23. - (void)viewWillAppear:(BOOL)animated {
  24. [super viewWillAppear:animated];
  25. _consoleOnly = self.configuration.displayConsoleOnly;
  26. [self showConsoleOptions:_consoleOnly animated:NO];
  27. NSInteger fontSize = self.configuration.consoleFontSize.integerValue;
  28. self.fontSizeLabel.text = [NSString stringWithFormat:@"%ld", fontSize];
  29. [self refreshFontLabel];
  30. }
  31. - (void)showConsoleOptions:(BOOL)consoleOnly animated:(BOOL)animated {
  32. if (consoleOnly) {
  33. [self cells:self.fullDisplayCells setHidden:YES];
  34. [self cells:self.consoleDisplayCells setHidden:NO];
  35. [self.graphicsTypeFullCell setAccessoryType:UITableViewCellAccessoryNone];
  36. [self.graphicsTypeConsoleCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  37. } else {
  38. [self cells:self.consoleDisplayCells setHidden:YES];
  39. [self cells:self.fullDisplayCells setHidden:NO];
  40. [self.graphicsTypeFullCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  41. [self.graphicsTypeConsoleCell setAccessoryType:UITableViewCellAccessoryNone];
  42. }
  43. [self hidePickersAnimated:animated];
  44. }
  45. - (void)refreshFontLabel {
  46. CGFloat size = self.fontPickerToggleCell.detailTextLabel.font.pointSize;
  47. self.fontPickerToggleCell.detailTextLabel.font = [UIFont fontWithName:self.configuration.consoleFont size:size];
  48. }
  49. #pragma mark - Properties
  50. - (void)setConsoleOnly:(BOOL)consoleOnly {
  51. if (_consoleOnly == consoleOnly) {
  52. return;
  53. }
  54. _consoleOnly = consoleOnly;
  55. self.configuration.displayConsoleOnly = consoleOnly;
  56. [self showConsoleOptions:consoleOnly animated:YES];
  57. }
  58. #pragma mark - Table delegate
  59. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  60. if ([tableView cellForRowAtIndexPath:indexPath] == self.graphicsTypeFullCell) {
  61. self.consoleOnly = NO;
  62. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  63. } else if ([tableView cellForRowAtIndexPath:indexPath] == self.graphicsTypeConsoleCell) {
  64. self.consoleOnly = YES;
  65. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  66. } else {
  67. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  68. }
  69. }
  70. #pragma mark - Picker delegate
  71. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  72. [super pickerView:pickerView didSelectRow:row inComponent:component];
  73. if (pickerView == self.fontPicker) {
  74. [self refreshFontLabel];
  75. }
  76. }
  77. #pragma mark - Event handlers
  78. - (IBAction)fontSizeStepperChanged:(UIStepper *)sender {
  79. NSAssert(sender == self.fontSizeStepper, @"Invalid sender");
  80. self.fontSizeLabel.text = [NSString stringWithFormat:@"%d", (int)sender.value];
  81. }
  82. @end